ZF-10044: Zend_Test_PHPUnit_Db_Operation_Truncate doesn't heed the AUTO_QUOTE_IDENTIFIERS config option
Description
Zend_Test_PHPUnit_Db_Operation_Truncate::truncate() calls Zend_Db_Adapter_Abstract::quoteIdentifier() and doesn't pass the second argument to allow the developer to control identifier quoting. This results in the truncate operation failing on (at least) Oracle.
Comments
Posted by Andrew Sharpe (andrewsharpe79) on 2010-07-19T17:06:56.000+0000
I'd still like to retain the truncate operation in the SimpleTester and the workaround I'm using ATM is rather cumbersome.
I have subclassed SimpleTester with the following:
class My_Test_PHPUnit_Db_SimpleTester extends Zend_Test_PHPUnit_Db_SimpleTester { public function __construct(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection) { parent::__construct($connection);
}
And also the Truncate operation:
class My_Test_PHPUnit_Db_Operation_Truncate extends Zend_Test_PHPUnit_Db_Operation_Truncate { protected function truncate(Zend_Db_Adapter_Abstract $db, $tableName) { // can't pass this through because when quoteIdentifier is called without // the second argument then quoting always happens => breakage // return parent::_truncate($db, $db->quoteIdentifier($tableName, true)); $tableName = $db->quoteIdentifier($tableName, true); if($db instanceof Zend_Db_Adapter_Pdo_Sqlite) { $db->query('DELETE FROM '.$tableName); } else if($db instanceof Zend_Db_Adapter_Db2) { if(strstr(PHP_OS, "WIN")) { $file = tempnam(sys_get_temp_dir(), "zendtestdbibm"); file_put_contents($file, ""); $db->query('IMPORT FROM '.$file.' OF DEL REPLACE INTO '.$tableName); unlink($file); } else { $db->query('IMPORT FROM /dev/null OF DEL REPLACE INTO '.$tableName); } } else if($this->isMssqlOrOracle($db)) { $db->query('TRUNCATE TABLE '.$tableName); } else { $db->query('TRUNCATE '.$tableName); } }
}
Here is the patch to ZF 1.9.5 to allow this to work (can't upgrade to ZF 10.x due to project priorities):
Index: php/library/Zend/Test/PHPUnit/Db/Operation/Truncate.php
--- php/library/Zend/Test/PHPUnit/Db/Operation/Truncate.php (revision 22559) +++ php/library/Zend/Test/PHPUnit/Db/Operation/Truncate.php (working copy) @@ -77,7 +77,7 @@ */ protected function _truncate(Zend_Db_Adapter_Abstract $db, $tableName) { - $tableName = $db->quoteIdentifier($tableName); + $tableName = $db->quoteIdentifier($tableName, true); if($db instanceof Zend_Db_Adapter_Pdo_Sqlite) { $db->query('DELETE FROM '.$tableName); } else if($db instanceof Zend_Db_Adapter_Db2) { @@ -111,4 +111,4 @@ $db instanceof Zend_Db_Adapter_Oracle ); } -} \ No newline at end of file +}
Unfortunately this system munges the formatting.
Posted by Ramon Henrique Ornelas (ramon) on 2011-01-22T06:16:36.000+0000
Fixed in trunk r23655 merged to release branch 1.11 r23656 - thanks.