[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 | ||
| Environment: |
PHP 5.3.1 (cli) (built: Feb 11 2010 02:32:22) |
||
| Attachments: |
|
| Description |
|
I reopen the Here is a simple test case: require_once('doctrine/lib/Doctrine.php');
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(){
$this->setTableName('record');
}
}
// Create the db
try {Doctrine::dropDatabases();}catch(Exception $e){} // Drop if exist :-)
Doctrine::createDatabases();Doctrine::createTablesFromArray(array('Record'));
// 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
|
| Comments |
| 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). 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). Regards |
| 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 ] |
|
Hi, 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. |