Zend Framework

Zend_Test_PHPUnit_Db_Operation_Truncate doesn't heed the AUTO_QUOTE_IDENTIFIERS config option

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.10.6
  • Fix Version/s: 1.11.3
  • Component/s: Zend_Test_PHPUnit
  • Labels:
    None

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.

Activity

Hide
Andrew Sharpe added a comment -

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.

Show
Andrew Sharpe added a comment - 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.
Hide
Ramon Henrique Ornelas added a comment -

Fixed in trunk r23655 merged to release branch 1.11 r23656 - thanks.

Show
Ramon Henrique Ornelas added a comment - Fixed in trunk r23655 merged to release branch 1.11 r23656 - thanks.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: