EllisLab text mark
Advanced Search
     
Bug in where_in() ?
Posted: 10 November 2012 05:20 AM   [ Ignore ]
Joined: 2012-09-08
4 posts

Hello,

I think I found a bug in where_in(), in deed, when i try to do this :

$this->db->where_in('id_product''SELECT id_product FROM ((SELECT COUNT(*) AS nb, id_product FROM test GROUP BY id_product) AS r) WHERE r.nb > 3');
$this->db->delete('test'); 

I must to do this :

$this->db->query('DELETE FROM test WHERE id_product IN (SELECT id_product FROM ((SELECT COUNT(*) AS nb, id_product FROM test GROUP BY id_product) AS r) WHERE r.nb > 3)'); 

Dragon.

 
Posted: 11 November 2012 08:02 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2009-10-22
64 posts

Make :
$this->db->last_query();
to see is correct your sql query.

 
Posted: 11 November 2012 03:17 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2012-09-08
4 posts

Yes CI generate this :

DELETE FROM `testWHERE `id_productIN ('SELECT id_product FROM ((SELECT COUNT(*) AS nb, id_product FROM test GROUP BY id_product) AS r) WHERE r.nb > 3'

Instead of this :

DELETE FROM `testWHERE `id_productIN (SELECT id_product FROM ((SELECT COUNT(*) AS nbid_product FROM test GROUP BY id_product) AS rWHERE r.nb 3

 

 
Posted: 11 November 2012 03:29 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Joined: 2011-02-23
882 posts

There’s no native support for nested queries in CI. There are some libraries that will help you create subqueries, or you can have a look at this link here http://heybigname.com/2009/09/18/using-code-igniters-active-record-class-to-create-subqueries

 Signature 

ignited Community Framework (WiP)  |  Read the User’s Guide. It won’t bite.

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

CI example .htaccess

 
Posted: 11 November 2012 03:33 PM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Joined: 2009-10-22
64 posts
PhilTem - 11 November 2012 03:29 PM

There’s no native support for nested queries in CI. There are some libraries that will help you create subqueries, or you can have a look at this link here http://heybigname.com/2009/09/18/using-code-igniters-active-record-class-to-create-subqueries

That’s very clever.

 
Posted: 11 November 2012 03:46 PM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Joined: 2012-09-08
4 posts

Tanks wink