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

Opened 11 years ago

Closed 11 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:

Description

This true at least with sqlite 3 from PDO extension.

Suppose you have the following DAO :

<?xml version="1.0"?>
<dao xmlns="http://jelix.org/ns/dao/1.0">
   <datasources>
      <primarytable name="tablealias" realname="products" primarykey="id" />
   </datasources>
   <record>
      <property name="id"   fieldname="id" datatype="autoincrement"/>
      <property name="alias" fieldname="alias" datatype="string"  required="true"/>
   </record>
</dao>

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: products.id

The generated SQL request is the following :

SELECT COUNT(DISTINCT products.id) 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 tablealias.id) as c  FROM products AS tablealias

See the corresponding joined patch.

Attachments (1)

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

Download all attachments as: .zip

Change History (5)

Changed 11 years ago by doubleface

comment:1 Changed 11 years ago by doubleface

  • review set to review?

comment:2 Changed 11 years ago by doubleface

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

comment:3 Changed 11 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.