From 4319d095f6cafc81f6011ac61973dd5d70db557c Mon Sep 17 00:00:00 2001 From: zYne Date: Mon, 29 Jan 2007 20:10:51 +0000 Subject: [PATCH] little sequence handling fix --- lib/Doctrine/Cache.php | 10 +++++----- lib/Doctrine/Connection.php | 4 ++++ lib/Doctrine/Connection/Mssql.php | 8 ++++---- lib/Doctrine/Sequence/Firebird.php | 10 +++++----- lib/Doctrine/Sequence/Mssql.php | 14 +++++++------- lib/Doctrine/Sequence/Sqlite.php | 2 +- tests/run.php | 11 ++++------- 7 files changed, 30 insertions(+), 29 deletions(-) diff --git a/lib/Doctrine/Cache.php b/lib/Doctrine/Cache.php index cfd4dbdc7..cdc59b949 100644 --- a/lib/Doctrine/Cache.php +++ b/lib/Doctrine/Cache.php @@ -32,9 +32,9 @@ */ class Doctrine_Cache { - protected $_options = array('size' => 1000, - 'lifetime' => 3600, - ); + protected $_options = array('size' => 1000, + 'lifetime' => 3600, + ); protected $_queries = array(); @@ -45,7 +45,7 @@ class Doctrine_Cache * @param string $query sql query string * @return void */ - public function process($query) + public function addQuery($query) { $this->queries[] = $query; } @@ -54,7 +54,7 @@ class Doctrine_Cache * * @return boolean */ - public function save() + public function processAll() { $content = file_get_contents($this->_statsFile); $queries = explode("\n", $content); diff --git a/lib/Doctrine/Connection.php b/lib/Doctrine/Connection.php index 9a46620c4..03b9c6a8e 100644 --- a/lib/Doctrine/Connection.php +++ b/lib/Doctrine/Connection.php @@ -97,6 +97,10 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ), 'wildcards' => array('%', '_') ); + /** + * @var array $serverInfo + */ + protected $serverInfo = array(); /** * @var array $availibleDrivers an array containing all availible drivers */ diff --git a/lib/Doctrine/Connection/Mssql.php b/lib/Doctrine/Connection/Mssql.php index dc2d7f1e1..5cc813a36 100644 --- a/lib/Doctrine/Connection/Mssql.php +++ b/lib/Doctrine/Connection/Mssql.php @@ -145,15 +145,15 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection * @return mixed array/string with version information or MDB2 error object */ public function getServerVersion($native = false) - { - if ($this->connected_server_info) { - $serverInfo = $this->connected_server_info; + { + if ($this->serverInfo) { + $serverInfo = $this->serverInfo; } else { $query = 'SELECT @@VERSION'; $serverInfo = $this->fetchOne($query); } // cache server_info - $this->connected_server_info = $serverInfo; + $this->serverInfo = $serverInfo; if ( ! $native) { if (preg_match('/([0-9]+)\.([0-9]+)\.([0-9]+)/', $serverInfo, $tmp)) { $serverInfo = array( diff --git a/lib/Doctrine/Sequence/Firebird.php b/lib/Doctrine/Sequence/Firebird.php index 81d8d037c..b36ca996a 100644 --- a/lib/Doctrine/Sequence/Firebird.php +++ b/lib/Doctrine/Sequence/Firebird.php @@ -47,7 +47,7 @@ class Doctrine_Sequence_Firebird extends Doctrine_Sequence $query = 'SELECT GEN_ID(' . $sequenceName . ', 1) as the_value FROM RDB$DATABASE'; try { - $result = $this->queryOne($query, 'integer'); + $result = $this->conn->fetchOne($query, 'integer'); } catch(Doctrine_Connection_Exception $e) { 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 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 @@ -86,14 +86,14 @@ class Doctrine_Sequence_Firebird extends Doctrine_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); $query = 'SELECT GEN_ID(' . $sequenceName . ', 0) as the_value FROM RDB$DATABASE'; try { - $value = $this->queryOne($query); + $value = $this->conn->fetchOne($query); } catch(Doctrine_Connection_Exception $e) { throw new Doctrine_Sequence_Exception('Unable to select from ' . $seqName); } diff --git a/lib/Doctrine/Sequence/Mssql.php b/lib/Doctrine/Sequence/Mssql.php index 404f8a7b6..d7de5a7a9 100644 --- a/lib/Doctrine/Sequence/Mssql.php +++ b/lib/Doctrine/Sequence/Mssql.php @@ -40,7 +40,7 @@ class Doctrine_Sequence_Mssql extends Doctrine_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); $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)) { $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 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) && ! is_null($serverInfo['major']) && $serverInfo['major'] >= 8) { @@ -105,7 +105,7 @@ class Doctrine_Sequence_Mssql extends Doctrine_Sequence $query = 'SELECT @@IDENTITY'; } - return $this->fetchOne($query); + return $this->conn->fetchOne($query); } /** * 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 */ - public function currID($seqName) + public function currId($seqName) { $this->warnings[] = 'database does not support getting current sequence value, the sequence value was incremented'; - return $this->nextID($seqName); + return $this->nextId($seqName); } } diff --git a/lib/Doctrine/Sequence/Sqlite.php b/lib/Doctrine/Sequence/Sqlite.php index ab728931e..c01b1be75 100644 --- a/lib/Doctrine/Sequence/Sqlite.php +++ b/lib/Doctrine/Sequence/Sqlite.php @@ -90,7 +90,7 @@ class Doctrine_Sequence_Sqlite extends Doctrine_Sequence */ public function lastInsertId($table = null, $field = null) { - return $this->conn->getDbh()->lastInsertID(); + return $this->conn->getDbh()->lastInsertId(); } /** * Returns the current id of a sequence diff --git a/tests/run.php b/tests/run.php index 2dd5be862..cd62dbf0c 100644 --- a/tests/run.php +++ b/tests/run.php @@ -1,7 +1,7 @@ addTestCase(new Doctrine_Expression_Pgsql_TestCase()); $test->addTestCase(new Doctrine_Expression_Oracle_TestCase()); $test->addTestCase(new Doctrine_Expression_Sqlite_TestCase()); - // Core $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_Condition_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_ShortAliases_TestCase()); - $test->addTestCase(new Doctrine_Query_Delete_TestCase()); $test->addTestCase(new Doctrine_Query_Where_TestCase()); - - $test->addTestCase(new Doctrine_Query_Limit_TestCase()); $test->addTestCase(new Doctrine_Query_IdentifierQuoting_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_Query_Subquery_TestCase()); - +$test->addTestCase(new Doctrine_Query_Orderby_TestCase()); // Cache tests