Permalink
Browse files

Added a Database_POD::sequence method and hooked into ::query, fixes …

…#2188
  • Loading branch information...
shadowhand committed Oct 28, 2010
1 parent 3d26998 commit 2cce7e2309347a11b409e560b80cb6c0f338b3c0
Showing with 20 additions and 1 deletion.
  1. +20 −1 classes/kohana/database/pdo.php
@@ -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);
@@ -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
@@ -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(),
);
}

0 comments on commit 2cce7e2

Please sign in to comment.