1
0
mirror of synced 2024-12-13 22:56:04 +03:00

- make more use of Doctrine internal methods

This commit is contained in:
lsmith 2007-01-05 22:04:11 +00:00
parent d4750eef1d
commit eae259a247
6 changed files with 26 additions and 31 deletions

View File

@ -87,7 +87,7 @@ class Doctrine_Connection_Firebird extends Doctrine_Connection
public function setCharset($charset) public function setCharset($charset)
{ {
$query = 'SET NAMES '.$this->dbh->quote($charset); $query = 'SET NAMES '.$this->dbh->quote($charset);
$this->dbh->query($query); $this->exec($query);
} }
/** /**
* Adds an driver-specific LIMIT clause to the query * Adds an driver-specific LIMIT clause to the query
@ -110,10 +110,8 @@ class Doctrine_Connection_Firebird extends Doctrine_Connection
* @param string $sequence * @param string $sequence
* @return integer * @return integer
*/ */
public function getNextID($sequence) public function nextId($sequence)
{ {
$stmt = $this->query('SELECT UNIQUE FROM ' . $sequence); return $this->fetchOne('SELECT UNIQUE FROM ' . $sequence);
$data = $stmt->fetch(PDO::FETCH_NUM);
return $data[0];
} }
} }

View File

@ -92,10 +92,17 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection
*/ */
public function nextId($sequence) public function nextId($sequence)
{ {
$this->query("INSERT INTO $sequence (vapor) VALUES (0)"); $sequenceName = $this->quoteIdentifier($this->getSequenceName($seqName), true);
$stmt = $this->query("SELECT @@IDENTITY FROM $sequence"); $seqcolName = $this->quoteIdentifier($this->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true);
$data = $stmt->fetch(PDO::FETCH_NUM); $query = 'INSERT INTO ' . $sequenceName . ' (' . $seqcolName . ') VALUES (0)';
return $data[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. * Adds an adapter-specific LIMIT clause to the SELECT statement.
@ -170,6 +177,6 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection
$query = "SELECT @@IDENTITY"; $query = "SELECT @@IDENTITY";
} }
return $this->queryOne($query); return $this->fetchOne($query);
} }
} }

View File

@ -99,7 +99,7 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common
public function setCharset($charset) public function setCharset($charset)
{ {
$query = 'SET NAMES '.$this->dbh->quote($charset); $query = 'SET NAMES '.$this->dbh->quote($charset);
$this->dbh->query($query); $this->exec($query);
} }
/** /**
* Returns the next free id of a sequence * 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); $sequenceName = $this->quoteIdentifier($this->getSequenceName($seqName), true);
$seqcolName = $this->quoteIdentifier($this->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true); $seqcolName = $this->quoteIdentifier($this->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true);
$query = 'INSERT INTO ' . $sequenceName . ' (' . $seqcolName . ') VALUES (NULL)'; $query = 'INSERT INTO ' . $sequenceName . ' (' . $seqcolName . ') VALUES (NULL)';
$result = $this->exec($query);
$value = $this->dbh->lastInsertId(); $value = $this->dbh->lastInsertId();
if (is_numeric($value)) { if (is_numeric($value)) {
$query = 'DELETE FROM ' . $sequenceName . ' WHERE ' . $seqcolName . ' < ' . $value; $query = 'DELETE FROM ' . $sequenceName . ' WHERE ' . $seqcolName . ' < ' . $value;
$result = $this->dbh->query($query); $result = $this->exec($query);
} }
return $value; return $value;
} }
@ -242,6 +242,6 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common
} }
$query = 'REPLACE INTO ' . $table . ' (' . $query . ') VALUES (' . $values . ')'; $query = 'REPLACE INTO ' . $table . ' (' . $query . ') VALUES (' . $values . ')';
return $this->dbh->exec($query); return $this->exec($query);
} }
} }

View File

@ -112,9 +112,7 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection
*/ */
public function nextId($sequence) public function nextId($sequence)
{ {
$stmt = $this->query('SELECT ' . $sequence . '.nextval FROM dual'); return $this->fetchOne('SELECT ' . $sequence . '.nextval FROM dual');
$data = $stmt->fetch(PDO::FETCH_NUM);
return $data[0];
} }
/** /**
* Returns the current id of a sequence * Returns the current id of a sequence
@ -126,8 +124,6 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection
public function currId($sequence) public function currId($sequence)
{ {
$sequence = $this->quoteIdentifier($this->getSequenceName($sequence), true); $sequence = $this->quoteIdentifier($this->getSequenceName($sequence), true);
$stmt = $this->query('SELECT ' . $sequence . '.currval FROM dual'); return $this->fetchOne('SELECT ' . $sequence . '.currval FROM dual');
$data = $stmt->fetch(PDO::FETCH_NUM);
return $data[0];
} }
} }

View File

@ -87,7 +87,7 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common
public function setCharset($charset) public function setCharset($charset)
{ {
$query = 'SET NAMES '.$this->dbh->quote($charset); $query = 'SET NAMES '.$this->dbh->quote($charset);
$this->dbh->query($query); $this->exec($query);
} }
/** /**
* returns the next value in the given sequence * returns the next value in the given sequence
@ -96,9 +96,7 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common
*/ */
public function nextId($sequence) public function nextId($sequence)
{ {
$stmt = $this->dbh->query("SELECT NEXTVAL('$sequence')"); return $this->fetchOne("SELECT NEXTVAL('$sequence')");
$data = $stmt->fetch(PDO::FETCH_NUM);
return $data[0];
} }
/** /**
* Returns the current id of a sequence * Returns the current id of a sequence
@ -108,9 +106,7 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common
*/ */
public function currId($sequence) public function currId($sequence)
{ {
$stmt = $this->dbh->query('SELECT last_value FROM '.$sequence); return $this->fetcOne('SELECT last_value FROM '.$sequence);
$data = $stmt->fetch(PDO::FETCH_NUM);
return $data[0];
} }
/** /**
* Changes a query string for various DBMS specific reasons * Changes a query string for various DBMS specific reasons

View File

@ -67,7 +67,7 @@ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common
'pattern_escaping' => false, '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['fixed_float'] = 0;
$this->options['database_path'] = ''; $this->options['database_path'] = '';
$this->options['database_extension'] = ''; $this->options['database_extension'] = '';
@ -95,8 +95,6 @@ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common
{ {
$sequence = $this->quoteIdentifier($sequence, true); $sequence = $this->quoteIdentifier($sequence, true);
$seqColumn = $this->quoteIdentifier($this->options['seqcol_name'], true); $seqColumn = $this->quoteIdentifier($this->options['seqcol_name'], true);
$stmt = $this->dbh->query('SELECT MAX(' . $seqColumn . ') FROM ' . $sequence); return $this->fetchOne('SELECT MAX(' . $seqColumn . ') FROM ' . $sequence);
$data = $stmt->fetch(PDO::FETCH_NUM);
return $data[0];
} }
} }