mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 17:16:18 +00:00
fixes #4832, lastinsert in postgres. test added
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7247 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
6eb4aba543
commit
91d86b91a4
2 changed files with 57 additions and 20 deletions
|
@ -332,7 +332,7 @@ class DboPostgres extends DboSource {
|
|||
*/
|
||||
function lastInsertId($source, $field = 'id') {
|
||||
$seq = $this->getSequence($source, $field);
|
||||
$data = $this->fetchRow("SELECT last_value AS max FROM \"{$seq}\"");
|
||||
$data = $this->fetchRow("SELECT currval('{$seq}') as max");
|
||||
return $data[0]['max'];
|
||||
}
|
||||
/**
|
||||
|
|
|
@ -44,15 +44,15 @@ require_once dirname(dirname(dirname(__FILE__))) . DS . 'models.php';
|
|||
class DboPostgresTestDb extends DboPostgres {
|
||||
/**
|
||||
* simulated property
|
||||
*
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $simulated = array();
|
||||
/**
|
||||
* execute method
|
||||
*
|
||||
* @param mixed $sql
|
||||
*
|
||||
* @param mixed $sql
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
|
@ -62,7 +62,7 @@ class DboPostgresTestDb extends DboPostgres {
|
|||
}
|
||||
/**
|
||||
* getLastQuery method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -79,25 +79,25 @@ class DboPostgresTestDb extends DboPostgres {
|
|||
class PostgresTestModel extends Model {
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
*
|
||||
* @var string 'PostgresTestModel'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'PostgresTestModel';
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
*
|
||||
* @var bool false
|
||||
* @access public
|
||||
*/
|
||||
var $useTable = false;
|
||||
/**
|
||||
* find method
|
||||
*
|
||||
* @param mixed $conditions
|
||||
* @param mixed $fields
|
||||
* @param mixed $order
|
||||
* @param mixed $recursive
|
||||
*
|
||||
* @param mixed $conditions
|
||||
* @param mixed $fields
|
||||
* @param mixed $order
|
||||
* @param mixed $recursive
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -106,11 +106,11 @@ class PostgresTestModel extends Model {
|
|||
}
|
||||
/**
|
||||
* findAll method
|
||||
*
|
||||
* @param mixed $conditions
|
||||
* @param mixed $fields
|
||||
* @param mixed $order
|
||||
* @param mixed $recursive
|
||||
*
|
||||
* @param mixed $conditions
|
||||
* @param mixed $fields
|
||||
* @param mixed $order
|
||||
* @param mixed $recursive
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -119,7 +119,7 @@ class PostgresTestModel extends Model {
|
|||
}
|
||||
/**
|
||||
* schema method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -160,6 +160,13 @@ class DboPostgresTest extends CakeTestCase {
|
|||
* @access public
|
||||
*/
|
||||
var $autoFixtures = false;
|
||||
/**
|
||||
* Fixtures
|
||||
*
|
||||
* @var object
|
||||
* @access public
|
||||
*/
|
||||
var $fixtures = array('core.user');
|
||||
/**
|
||||
* Actual DB connection used in testing
|
||||
*
|
||||
|
@ -251,7 +258,7 @@ class DboPostgresTest extends CakeTestCase {
|
|||
}
|
||||
/**
|
||||
* testColumnParsing method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -265,7 +272,7 @@ class DboPostgresTest extends CakeTestCase {
|
|||
}
|
||||
/**
|
||||
* testValueQuoting method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -275,6 +282,36 @@ class DboPostgresTest extends CakeTestCase {
|
|||
$this->assertEqual($this->db2->value('', 'float'), "DEFAULT");
|
||||
$this->assertEqual($this->db2->value('0.0', 'float'), "'0.0'");
|
||||
}
|
||||
/**
|
||||
* testLastInsertIdMultipleInsert method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testLastInsertIdMultipleInsert() {
|
||||
$this->loadFixtures('User');
|
||||
|
||||
$User =& new User();
|
||||
$db1 = ConnectionManager::getDataSource('test_suite');
|
||||
if (PHP5) {
|
||||
$db2 = clone $db1;
|
||||
} else {
|
||||
$db2 = $db1;
|
||||
}
|
||||
|
||||
$db2->connect();
|
||||
$this->assertNotEqual($db1->connection, $db2->connection);
|
||||
|
||||
$db1->truncate($User->useTable);
|
||||
|
||||
$table = $db1->fullTableName($User->useTable, false);
|
||||
$db1->execute("INSERT INTO {$table} (\"user\", password)"
|
||||
. " VALUES ('mariano', '5f4dcc3b5aa765d61d8327deb882cf99')");
|
||||
$db2->execute("INSERT INTO {$table} (\"user\", password)"
|
||||
. " VALUES ('hoge', '5f4dcc3b5aa765d61d8327deb882cf99')");
|
||||
$this->assertEqual($db1->lastInsertId($table), 1);
|
||||
$this->assertEqual($db2->lastInsertId($table), 2);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Add table
Reference in a new issue