Skip to content

Commit

Permalink
Added a Database_POD::sequence method and hooked into ::query, fixes …
Browse files Browse the repository at this point in the history
…#2188
  • Loading branch information
Woody Gilk committed Oct 28, 2010
1 parent 3d26998 commit 2cce7e2
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion classes/kohana/database/pdo.php
Expand Up @@ -13,6 +13,9 @@ class Kohana_Database_PDO extends Database {
// PDO uses no quoting for identifiers
protected $_identifier = '';

// Sequence name for getting the last insert ID
protected $_sequence = NULL;

protected function __construct($name, array $config)
{
parent::__construct($name, $config);
Expand Down Expand Up @@ -87,6 +90,22 @@ public function set_charset($charset)
$this->_connection->exec('SET NAMES '.$this->quote($charset));
}

/**
* Set the sequence name for getting the last insert ID.
*
* [!!] This is only necessary when using Postgre.
*
* @param string new sequence name
* @return $this
*/
public function sequence($name = NULL)
{
// Set the new sequence name
$this->_sequence = $name;

return $this;
}

public function query($type, $sql, $as_object = FALSE, array $params = NULL)
{
// Make sure the database is connected
Expand Down Expand Up @@ -152,7 +171,7 @@ public function query($type, $sql, $as_object = FALSE, array $params = NULL)
{
// Return a list of insert id and rows created
return array(
$this->_connection->lastInsertId(),
$this->_connection->lastInsertId($this->_sequence),
$result->rowCount(),
);
}
Expand Down

0 comments on commit 2cce7e2

Please sign in to comment.