1
0
mirror of synced 2025-01-31 20:41:44 +03:00

little sequence handling fix

This commit is contained in:
zYne 2007-01-29 20:10:51 +00:00
parent 360c8ea207
commit 4319d095f6
7 changed files with 30 additions and 29 deletions

View File

@ -45,7 +45,7 @@ class Doctrine_Cache
* @param string $query sql query string * @param string $query sql query string
* @return void * @return void
*/ */
public function process($query) public function addQuery($query)
{ {
$this->queries[] = $query; $this->queries[] = $query;
} }
@ -54,7 +54,7 @@ class Doctrine_Cache
* *
* @return boolean * @return boolean
*/ */
public function save() public function processAll()
{ {
$content = file_get_contents($this->_statsFile); $content = file_get_contents($this->_statsFile);
$queries = explode("\n", $content); $queries = explode("\n", $content);

View File

@ -97,6 +97,10 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
), ),
'wildcards' => array('%', '_') 'wildcards' => array('%', '_')
); );
/**
* @var array $serverInfo
*/
protected $serverInfo = array();
/** /**
* @var array $availibleDrivers an array containing all availible drivers * @var array $availibleDrivers an array containing all availible drivers
*/ */

View File

@ -146,14 +146,14 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection
*/ */
public function getServerVersion($native = false) public function getServerVersion($native = false)
{ {
if ($this->connected_server_info) { if ($this->serverInfo) {
$serverInfo = $this->connected_server_info; $serverInfo = $this->serverInfo;
} else { } else {
$query = 'SELECT @@VERSION'; $query = 'SELECT @@VERSION';
$serverInfo = $this->fetchOne($query); $serverInfo = $this->fetchOne($query);
} }
// cache server_info // cache server_info
$this->connected_server_info = $serverInfo; $this->serverInfo = $serverInfo;
if ( ! $native) { if ( ! $native) {
if (preg_match('/([0-9]+)\.([0-9]+)\.([0-9]+)/', $serverInfo, $tmp)) { if (preg_match('/([0-9]+)\.([0-9]+)\.([0-9]+)/', $serverInfo, $tmp)) {
$serverInfo = array( $serverInfo = array(

View File

@ -47,7 +47,7 @@ class Doctrine_Sequence_Firebird extends Doctrine_Sequence
$query = 'SELECT GEN_ID(' . $sequenceName . ', 1) as the_value FROM RDB$DATABASE'; $query = 'SELECT GEN_ID(' . $sequenceName . ', 1) as the_value FROM RDB$DATABASE';
try { try {
$result = $this->queryOne($query, 'integer'); $result = $this->conn->fetchOne($query, 'integer');
} catch(Doctrine_Connection_Exception $e) { } catch(Doctrine_Connection_Exception $e) {
if ($onDemand && $e->getPortableCode() == Doctrine::ERR_NOSUCHTABLE) { if ($onDemand && $e->getPortableCode() == Doctrine::ERR_NOSUCHTABLE) {
@ -75,9 +75,9 @@ class Doctrine_Sequence_Firebird extends Doctrine_Sequence
* @param string name of the table into which a new row was inserted * @param string name of the table into which a new row was inserted
* @param string name of the field into which a new row was inserted * @param string name of the field into which a new row was inserted
*/ */
public function lastInsertID($table = null, $field = null) public function lastInsertId($table = null, $field = null)
{ {
throw new Doctrine_Sequence_Exception('method not implemented'); return $this->conn->getDbh()->lastInsertId();
} }
/** /**
* Returns the current id of a sequence * Returns the current id of a sequence
@ -86,14 +86,14 @@ class Doctrine_Sequence_Firebird extends Doctrine_Sequence
* *
* @return integer current id in the given sequence * @return integer current id in the given sequence
*/ */
public function currID($seqName) public function currId($seqName)
{ {
$sequenceName = $this->conn->quoteIdentifier($this->getSequenceName($seqName), true); $sequenceName = $this->conn->quoteIdentifier($this->getSequenceName($seqName), true);
$query = 'SELECT GEN_ID(' . $sequenceName . ', 0) as the_value FROM RDB$DATABASE'; $query = 'SELECT GEN_ID(' . $sequenceName . ', 0) as the_value FROM RDB$DATABASE';
try { try {
$value = $this->queryOne($query); $value = $this->conn->fetchOne($query);
} catch(Doctrine_Connection_Exception $e) { } catch(Doctrine_Connection_Exception $e) {
throw new Doctrine_Sequence_Exception('Unable to select from ' . $seqName); throw new Doctrine_Sequence_Exception('Unable to select from ' . $seqName);
} }

View File

@ -40,7 +40,7 @@ class Doctrine_Sequence_Mssql extends Doctrine_Sequence
* *
* @return integer next id in the given sequence * @return integer next id in the given sequence
*/ */
public function nextID($seqName, $ondemand = true) public function nextId($seqName, $ondemand = true)
{ {
$sequenceName = $this->conn->quoteIdentifier($this->getSequenceName($seqName), true); $sequenceName = $this->conn->quoteIdentifier($this->getSequenceName($seqName), true);
$seqcolName = $this->conn->quoteIdentifier($this->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true); $seqcolName = $this->conn->quoteIdentifier($this->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true);
@ -71,7 +71,7 @@ class Doctrine_Sequence_Mssql extends Doctrine_Sequence
} }
} }
$value = $this->lastInsertID($sequenceName); $value = $this->lastInsertId($sequenceName);
if (is_numeric($value)) { if (is_numeric($value)) {
$query = 'DELETE FROM ' . $sequenceName . ' WHERE ' . $seqcolName . ' < ' . $value; $query = 'DELETE FROM ' . $sequenceName . ' WHERE ' . $seqcolName . ' < ' . $value;
@ -92,9 +92,9 @@ class Doctrine_Sequence_Mssql extends Doctrine_Sequence
* @param string name of the table into which a new row was inserted * @param string name of the table into which a new row was inserted
* @param string name of the field into which a new row was inserted * @param string name of the field into which a new row was inserted
*/ */
public function lastInsertID($table = null, $field = null) public function lastInsertId($table = null, $field = null)
{ {
$serverInfo = $this->getServerVersion(); $serverInfo = $this->conn->getServerVersion();
if (is_array($serverInfo) if (is_array($serverInfo)
&& ! is_null($serverInfo['major']) && ! is_null($serverInfo['major'])
&& $serverInfo['major'] >= 8) { && $serverInfo['major'] >= 8) {
@ -105,7 +105,7 @@ class Doctrine_Sequence_Mssql extends Doctrine_Sequence
$query = 'SELECT @@IDENTITY'; $query = 'SELECT @@IDENTITY';
} }
return $this->fetchOne($query); return $this->conn->fetchOne($query);
} }
/** /**
* Returns the current id of a sequence * Returns the current id of a sequence
@ -114,10 +114,10 @@ class Doctrine_Sequence_Mssql extends Doctrine_Sequence
* *
* @return integer current id in the given sequence * @return integer current id in the given sequence
*/ */
public function currID($seqName) public function currId($seqName)
{ {
$this->warnings[] = 'database does not support getting current $this->warnings[] = 'database does not support getting current
sequence value, the sequence value was incremented'; sequence value, the sequence value was incremented';
return $this->nextID($seqName); return $this->nextId($seqName);
} }
} }

View File

@ -90,7 +90,7 @@ class Doctrine_Sequence_Sqlite extends Doctrine_Sequence
*/ */
public function lastInsertId($table = null, $field = null) public function lastInsertId($table = null, $field = null)
{ {
return $this->conn->getDbh()->lastInsertID(); return $this->conn->getDbh()->lastInsertId();
} }
/** /**
* Returns the current id of a sequence * Returns the current id of a sequence

View File

@ -1,7 +1,7 @@
<?php <?php
ob_start(); ob_start();
ini_set('max_execution_time',900); ini_set('max_execution_time', 900);
function autoload($class) { function autoload($class) {
if(strpos($class, 'TestCase') === false) if(strpos($class, 'TestCase') === false)
@ -135,7 +135,6 @@ $test->addTestCase(new Doctrine_Expression_Pgsql_TestCase());
$test->addTestCase(new Doctrine_Expression_Oracle_TestCase()); $test->addTestCase(new Doctrine_Expression_Oracle_TestCase());
$test->addTestCase(new Doctrine_Expression_Sqlite_TestCase()); $test->addTestCase(new Doctrine_Expression_Sqlite_TestCase());
// Core // Core
$test->addTestCase(new Doctrine_Access_TestCase()); $test->addTestCase(new Doctrine_Access_TestCase());
@ -197,14 +196,11 @@ $test->addTestCase(new Doctrine_Query_MultiJoin_TestCase());
$test->addTestCase(new Doctrine_Query_ReferenceModel_TestCase()); $test->addTestCase(new Doctrine_Query_ReferenceModel_TestCase());
$test->addTestCase(new Doctrine_Query_Condition_TestCase()); $test->addTestCase(new Doctrine_Query_Condition_TestCase());
$test->addTestCase(new Doctrine_Query_ComponentAlias_TestCase()); $test->addTestCase(new Doctrine_Query_ComponentAlias_TestCase());
$test->addTestCase(new Doctrine_Query_Subquery_TestCase());
$test->addTestCase(new Doctrine_Query_TestCase()); $test->addTestCase(new Doctrine_Query_TestCase());
$test->addTestCase(new Doctrine_Query_ShortAliases_TestCase()); $test->addTestCase(new Doctrine_Query_ShortAliases_TestCase());
$test->addTestCase(new Doctrine_Query_Delete_TestCase()); $test->addTestCase(new Doctrine_Query_Delete_TestCase());
$test->addTestCase(new Doctrine_Query_Where_TestCase()); $test->addTestCase(new Doctrine_Query_Where_TestCase());
$test->addTestCase(new Doctrine_Query_Limit_TestCase()); $test->addTestCase(new Doctrine_Query_Limit_TestCase());
$test->addTestCase(new Doctrine_Query_IdentifierQuoting_TestCase()); $test->addTestCase(new Doctrine_Query_IdentifierQuoting_TestCase());
$test->addTestCase(new Doctrine_Query_Update_TestCase()); $test->addTestCase(new Doctrine_Query_Update_TestCase());
@ -219,8 +215,9 @@ $test->addTestCase(new Doctrine_Query_JoinCondition_TestCase());
$test->addTestCase(new Doctrine_ColumnAlias_TestCase()); $test->addTestCase(new Doctrine_ColumnAlias_TestCase());
$test->addTestCase(new Doctrine_Query_Subquery_TestCase());
$test->addTestCase(new Doctrine_Query_Orderby_TestCase());
// Cache tests // Cache tests