is not used any more and exists only for history. Post new tickets on the Github account. n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Opened 12 years ago

Closed 12 years ago

#1010 closed bug (fixed)

DISTINCT does not work if the table is aliased

Reported by: doubleface Owned by: doubleface
Priority: normal Milestone: Jelix 1.1.4
Component: jelix:dao Version: 1.1.3
Severity: normal Keywords:
Cc: Blocked By:
Blocking: Documentation needed: no
Hosting Provider: Php version:


This true at least with sqlite 3 from PDO extension.

Suppose you have the following DAO :

<?xml version="1.0"?>
<dao xmlns="">
      <primarytable name="tablealias" realname="products" primarykey="id" />
      <property name="id"   fieldname="id" datatype="autoincrement"/>
      <property name="alias" fieldname="alias" datatype="string"  required="true"/>

If you try to run the following code :

$factory = jDao::get('products', 'testapp_sqlite');
$condition = new jDaoConditions();
$factory->countBy($condition, 'id');

you get the following error message :

[exception HY000] SQLSTATE[HY000]: General error: 1 no such column:

The generated SQL request is the following :

SELECT COUNT(DISTINCT as c  FROM products AS tablealias

The real name of the table has been used instead of the alias and it does not work with sqlite (I don't know for mySQL or postgreSQL)

I think the generated request should be :

SELECT COUNT(DISTINCT as c  FROM products AS tablealias

See the corresponding joined patch.

Attachments (1)

distinct.patch (717 bytes) - added by doubleface 12 years ago.

Download all attachments as: .zip

Change History (5)

Changed 12 years ago by doubleface

comment:1 Changed 12 years ago by doubleface

  • review set to review?

comment:2 Changed 12 years ago by doubleface

  • Owner set to doubleface
  • Status changed from new to assigned

comment:3 Changed 12 years ago by laurentj

  • Milestone set to Jelix 1.1.4
  • review changed from review? to review+
  • Version set to 1.1.3

ok for me. should be land into 1.1.x branch and trunk

Note: See TracTickets for help on using tickets.