Added truncate tests to firebird/sqlite test suites

This commit is contained in:
Timothy Warren 2012-03-12 16:09:12 -04:00
parent 9d33c5e8f0
commit d74e1907dd
6 changed files with 27 additions and 13 deletions

View File

@ -54,11 +54,11 @@ abstract class DB_PDO extends PDO {
$this->statement =& $query; $this->statement =& $query;
/*if( ! (is_array($data) || is_object($data))) if( ! (is_array($data) || is_object($data)))
{ {
trigger_error("Invalid data argument"); trigger_error("Invalid data argument");
return FALSE; return FALSE;
}*/ }
// Bind the parameters // Bind the parameters
foreach($data as $k => $value) foreach($data as $k => $value)
@ -125,15 +125,18 @@ abstract class DB_PDO extends PDO {
* @param PDOStatement $statement * @param PDOStatement $statement
* @return int * @return int
*/ */
public function affected_rows($statement) public function affected_rows($statement='')
{ {
$this->statement = $statement; if ( ! empty($statement))
{
$this->statement = $statement;
}
// Execute the query // Execute the query
$this->statement->execute(); $this->statement->execute();
// Return number of rows affected // Return number of rows affected
return $this->statement->rowCount; return $this->statement->rowCount();
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------

View File

@ -65,7 +65,7 @@ class firebird extends DB_PDO {
{ {
// Firebird lacka a truncate command // Firebird lacka a truncate command
$sql = 'DELETE FROM "'.$table.'"'; $sql = 'DELETE FROM "'.$table.'"';
$this->query($sql); $this->statement = $this->query($sql);
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------

View File

@ -46,13 +46,11 @@ class SQLite extends DB_PDO {
{ {
// SQLite has a TRUNCATE optimization, // SQLite has a TRUNCATE optimization,
// but no support for the actual command. // but no support for the actual command.
$sql = 'DELETE FROM :table'; $sql = 'DELETE FROM "'.$table.'"';
$this->prepare_query($sql, array( $this->statement = $this->query($sql);
':table' => $table
));
$this->statement->execute(); return $this->statement;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------

View File

@ -103,6 +103,13 @@ class FirebirdTest extends UnitTestCase {
$this->assertTrue($table_exists); $this->assertTrue($table_exists);
}*/ }*/
function TestTruncate()
{
$this->db->truncate('create_test');
$this->assertTrue($this->db->affected_rows() > 0);
}
function TestCommitTransaction() function TestCommitTransaction()
{ {
$res = $this->db->beginTransaction(); $res = $this->db->beginTransaction();

View File

@ -79,6 +79,12 @@ class SQLiteTest extends UnitTestCase {
$this->assertEqual($dbs['create_test'], 'CREATE TABLE "create_test" (id INTEGER PRIMARY KEY, key TEXT , val TEXT )'); $this->assertEqual($dbs['create_test'], 'CREATE TABLE "create_test" (id INTEGER PRIMARY KEY, key TEXT , val TEXT )');
} }
function TestTruncate()
{
$this->db->truncate('create_test');
$this->assertIsA($this->db->affected_rows(), 'int');
}
function TestPreparedStatements() function TestPreparedStatements()
{ {
$sql = <<<SQL $sql = <<<SQL

Binary file not shown.