diff --git a/lib/Doctrine/Connection/Firebird.php b/lib/Doctrine/Connection/Firebird.php index d2bdd6fd6..837caf151 100644 --- a/lib/Doctrine/Connection/Firebird.php +++ b/lib/Doctrine/Connection/Firebird.php @@ -87,7 +87,7 @@ class Doctrine_Connection_Firebird extends Doctrine_Connection public function setCharset($charset) { $query = 'SET NAMES '.$this->dbh->quote($charset); - $this->dbh->query($query); + $this->exec($query); } /** * Adds an driver-specific LIMIT clause to the query @@ -110,10 +110,8 @@ class Doctrine_Connection_Firebird extends Doctrine_Connection * @param string $sequence * @return integer */ - public function getNextID($sequence) + public function nextId($sequence) { - $stmt = $this->query('SELECT UNIQUE FROM ' . $sequence); - $data = $stmt->fetch(PDO::FETCH_NUM); - return $data[0]; + return $this->fetchOne('SELECT UNIQUE FROM ' . $sequence); } } diff --git a/lib/Doctrine/Connection/Mssql.php b/lib/Doctrine/Connection/Mssql.php index 538c81a6a..c3612c097 100644 --- a/lib/Doctrine/Connection/Mssql.php +++ b/lib/Doctrine/Connection/Mssql.php @@ -92,10 +92,17 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection */ public function nextId($sequence) { - $this->query("INSERT INTO $sequence (vapor) VALUES (0)"); - $stmt = $this->query("SELECT @@IDENTITY FROM $sequence"); - $data = $stmt->fetch(PDO::FETCH_NUM); - return $data[0]; + $sequenceName = $this->quoteIdentifier($this->getSequenceName($seqName), true); + $seqcolName = $this->quoteIdentifier($this->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true); + $query = 'INSERT INTO ' . $sequenceName . ' (' . $seqcolName . ') VALUES (0)'; + $result = $this->exec($query); + $value = $this->dbh->lastInsertId(); + + if (is_numeric($value)) { + $query = 'DELETE FROM ' . $sequenceName . ' WHERE ' . $seqcolName . ' < ' . $value; + $result = $this->exec($query); + } + return $value; } /** * Adds an adapter-specific LIMIT clause to the SELECT statement. @@ -170,6 +177,6 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection $query = "SELECT @@IDENTITY"; } - return $this->queryOne($query); + return $this->fetchOne($query); } } diff --git a/lib/Doctrine/Connection/Mysql.php b/lib/Doctrine/Connection/Mysql.php index 507c3ad91..903ffe0b6 100644 --- a/lib/Doctrine/Connection/Mysql.php +++ b/lib/Doctrine/Connection/Mysql.php @@ -99,7 +99,7 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common public function setCharset($charset) { $query = 'SET NAMES '.$this->dbh->quote($charset); - $this->dbh->query($query); + $this->exec($query); } /** * Returns the next free id of a sequence @@ -118,12 +118,12 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common $sequenceName = $this->quoteIdentifier($this->getSequenceName($seqName), true); $seqcolName = $this->quoteIdentifier($this->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true); $query = 'INSERT INTO ' . $sequenceName . ' (' . $seqcolName . ') VALUES (NULL)'; - + $result = $this->exec($query); $value = $this->dbh->lastInsertId(); if (is_numeric($value)) { $query = 'DELETE FROM ' . $sequenceName . ' WHERE ' . $seqcolName . ' < ' . $value; - $result = $this->dbh->query($query); + $result = $this->exec($query); } return $value; } @@ -242,6 +242,6 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common } $query = 'REPLACE INTO ' . $table . ' (' . $query . ') VALUES (' . $values . ')'; - return $this->dbh->exec($query); + return $this->exec($query); } } diff --git a/lib/Doctrine/Connection/Oracle.php b/lib/Doctrine/Connection/Oracle.php index 33ee0a696..6e89d9ab6 100644 --- a/lib/Doctrine/Connection/Oracle.php +++ b/lib/Doctrine/Connection/Oracle.php @@ -112,9 +112,7 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection */ public function nextId($sequence) { - $stmt = $this->query('SELECT ' . $sequence . '.nextval FROM dual'); - $data = $stmt->fetch(PDO::FETCH_NUM); - return $data[0]; + return $this->fetchOne('SELECT ' . $sequence . '.nextval FROM dual'); } /** * Returns the current id of a sequence @@ -126,8 +124,6 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection public function currId($sequence) { $sequence = $this->quoteIdentifier($this->getSequenceName($sequence), true); - $stmt = $this->query('SELECT ' . $sequence . '.currval FROM dual'); - $data = $stmt->fetch(PDO::FETCH_NUM); - return $data[0]; + return $this->fetchOne('SELECT ' . $sequence . '.currval FROM dual'); } } diff --git a/lib/Doctrine/Connection/Pgsql.php b/lib/Doctrine/Connection/Pgsql.php index eacecbea0..7230a861f 100644 --- a/lib/Doctrine/Connection/Pgsql.php +++ b/lib/Doctrine/Connection/Pgsql.php @@ -87,7 +87,7 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common public function setCharset($charset) { $query = 'SET NAMES '.$this->dbh->quote($charset); - $this->dbh->query($query); + $this->exec($query); } /** * returns the next value in the given sequence @@ -96,9 +96,7 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common */ public function nextId($sequence) { - $stmt = $this->dbh->query("SELECT NEXTVAL('$sequence')"); - $data = $stmt->fetch(PDO::FETCH_NUM); - return $data[0]; + return $this->fetchOne("SELECT NEXTVAL('$sequence')"); } /** * Returns the current id of a sequence @@ -108,9 +106,7 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common */ public function currId($sequence) { - $stmt = $this->dbh->query('SELECT last_value FROM '.$sequence); - $data = $stmt->fetch(PDO::FETCH_NUM); - return $data[0]; + return $this->fetcOne('SELECT last_value FROM '.$sequence); } /** * Changes a query string for various DBMS specific reasons diff --git a/lib/Doctrine/Connection/Sqlite.php b/lib/Doctrine/Connection/Sqlite.php index 5e44663a2..e1ecf0f58 100644 --- a/lib/Doctrine/Connection/Sqlite.php +++ b/lib/Doctrine/Connection/Sqlite.php @@ -67,7 +67,7 @@ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common 'pattern_escaping' => false, ); /** - $this->options['base_transaction_name'] = '___php_MDB2_sqlite_auto_commit_off'; + $this->options['base_transaction_name'] = '___php_Doctrine_sqlite_auto_commit_off'; $this->options['fixed_float'] = 0; $this->options['database_path'] = ''; $this->options['database_extension'] = ''; @@ -95,8 +95,6 @@ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common { $sequence = $this->quoteIdentifier($sequence, true); $seqColumn = $this->quoteIdentifier($this->options['seqcol_name'], true); - $stmt = $this->dbh->query('SELECT MAX(' . $seqColumn . ') FROM ' . $sequence); - $data = $stmt->fetch(PDO::FETCH_NUM); - return $data[0]; + return $this->fetchOne('SELECT MAX(' . $seqColumn . ') FROM ' . $sequence); } }