[DC-727] ReOpen DC-46 - Unexpected behavior with whereIn() and empty array Created: 11/Jun/10  Updated: 12/Oct/11

Status: Open
Project: Doctrine 1
Component/s: Query
Affects Version/s: 1.2.1, 1.2.2, 1.2.3
Fix Version/s: None

Type: Bug Priority: Major
Reporter: David Jeanmonod Assignee: Jonathan H. Wage
Resolution: Unresolved Votes: 3
Labels: None

PHP 5.3.1 (cli) (built: Feb 11 2010 02:32:22)
mysql Ver 14.14 Distrib 5.1.41, for apple-darwin9.5.0 (i386) using readline 5.1
Doctrine version 1.2.2 from SVN: http://doctrine.mirror.svn.symfony-project.com/tags/1.2.2/lib/Doctrine.php

Attachments: Text File DC-727_refactored.patch     Text File DC-727_with_duplicates.patch     File DC727TestCase.php     File DC727TestCase_more_specific.php    


I reopen the DC-46 as it'seems not fix at all.
When I do a whereIn with empty array, the condition is just drop and I get no Exception.

Here is a simple test case:

spl_autoload_register(array('Doctrine', 'autoload'));
$manager = Doctrine_Manager::getInstance();
$manager->setAttribute(Doctrine::ATTR_EXPORT, Doctrine::EXPORT_ALL);
$conn = Doctrine_Manager::connection('mysql://root:root@localhost/test_doctrine');
echo "Connection is set up\n";

class Record extends Doctrine_Record {
    public function setTableDefinition(){

// Create the db
try {Doctrine::dropDatabases();}catch(Exception $e){} // Drop if exist :-)

// Test
echo Doctrine::getTable('Record')->createQuery()->select('id')->whereIn('id', array())->getSqlQuery() , "\n";
echo Doctrine::getTable('Record')->createQuery()->select('id')->whereIn('id', array())->fetchArray() , "\n";

// Result is:
// SELECT r.id AS r__id FROM record r
// Array

Comment by Guilliam X [ 16/Jun/10 ]

The problem is that the change for "new" behavior (throw exception instead of return unchanged query) was only done in _processWhereIn() but not cascaded to andWhereIn() and orWhereIn() (another example we should avoid code duplication).
The patch is simple, but it causes Doctrine_Ticket_1558_TestCase to fail. Indeed that (old) test expects the "old" behavior (return unchanged query, don't throw exception)... So the 2 fixes are incompatible, you'll have to choose :/

I still attach a new test case and 2 versions of a patch (the first one just applies changes of _processWhereIn also to the 2 other functions but adds more duplicate code, the second is a little refactored and seems better to me).


Comment by Guilliam X [ 16/Jun/10 ]

added a more specific test case (expects Doctrine_Query_Exception instead of simple Exception)

Comment by Jan Sch├╝tze [ 22/Nov/10 ]


the issue is still present in 1.2.3. Are there any plans to apply it?

Kind regards,

Comment by Jim Persson [ 12/Oct/11 ]

I would like to add that this also applies to delete-queries which can cause serious data loss.
We had a case where a table of serialized data was completely emptied which caused a database cascade that deleted quite a lot of data.

Generated at Sun Aug 30 14:10:53 EDT 2015 using JIRA 6.4.10#64025-sha1:5b8b74079161cd76a20ab66dda52747ee6701bd6.