ZF-10044: Zend_Test_PHPUnit_Db_Operation_Truncate doesn't heed the AUTO_QUOTE_IDENTIFIERS config option

Issue Type: Bug Created: 2010-06-23T23:44:14.000+0000 Last Updated: 2011-01-22T06:16:36.000+0000 Status: Resolved Fix version(s): - 1.11.3 (01/Feb/11)

Reporter: Andrew Sharpe (andrewsharpe79) Assignee: Ramon Henrique Ornelas (ramon) Tags: - Zend_Test_PHPUnit

Related issues: Attachments:


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.


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);

    $this->setUpOperation = new PHPUnit_Extensions_Database_Operation_Composite(array(
        new My_Test_PHPUnit_Db_Operation_Truncate(),
        new Zend_Test_PHPUnit_Db_Operation_Insert(),


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); } }

private function _isMssqlOrOracle_($db) {
    return (
        $db instanceof Zend_Db_Adapter_Pdo_Mssql ||
        $db instanceof Zend_Db_Adapter_Sqlsrv ||
        $db instanceof Zend_Db_Adapter_Pdo_Oci ||
        $db instanceof Zend_Db_Adapter_Oracle


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.

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.