Skip to content

Commit

Permalink
Fixing execute() $this->_result was not instance of PDOStatement afte…
Browse files Browse the repository at this point in the history
…r queries other then SELECT, lastAffected() now returns correct integer
  • Loading branch information
ceeram committed Oct 20, 2011
1 parent a7404e8 commit 2890e66
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/Cake/Model/Datasource/DboSource.php
Expand Up @@ -440,7 +440,9 @@ protected function _execute($sql, $params = array(), $prepareOptions = array())
}
if (!$query->columnCount()) {
$query->closeCursor();
return true;
if (!$query->rowCount()) {
return true;
}
}
return $query;
} catch (PDOException $e) {
Expand Down
26 changes: 25 additions & 1 deletion lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php
Expand Up @@ -223,6 +223,30 @@ public function testTinyintCasting() {
$this->assertIdentical($result['Tinyint']['small_int'], '0');
$this->model->deleteAll(true);

$this->Dbo->rawQuery('DROP TABLE ' . $this->Dbo->fullTableName($tableName));
}
/**
* testLastAffected method
*
*
* @return void
*/
public function testLastAffected() {
$this->Dbo->cacheSources = false;
$tableName = 'tinyint_' . uniqid();
$this->Dbo->rawQuery('CREATE TABLE ' . $this->Dbo->fullTableName($tableName) . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id));');

$this->model = new CakeTestModel(array(
'name' => 'Tinyint', 'table' => $tableName, 'ds' => 'test'
));

$this->assertTrue((bool)$this->model->save(array('bool' => 5, 'small_int' => 5)));
$this->assertEqual(1, $this->model->find('count'));
$this->model->deleteAll(true);
$result = $this->Dbo->lastAffected();
$this->assertEqual(1, $result);
$this->assertEqual(0, $this->model->find('count'));

$this->Dbo->rawQuery('DROP TABLE ' . $this->Dbo->fullTableName($tableName));
}

Expand Down Expand Up @@ -2554,7 +2578,7 @@ public function testSchema() {
*/
public function testDropSchemaNoSchema() {
$result = $this->Dbo->dropSchema(null);
}
}

/**
* testOrderParsing method
Expand Down

0 comments on commit 2890e66

Please sign in to comment.