Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for Postgresql PDO::lastInsertId() #147

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/Pixie/QueryBuilder/QueryBuilderHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public function subQuery(QueryBuilderHandler $queryBuilder, $alias = null)
*
* @return array|string
*/
private function doInsert($data, $type)
private function doInsert($data, $type, $sequence = null)
{
$eventResult = $this->fireEvents('before-insert');
if (!is_null($eventResult)) {
Expand All @@ -324,7 +324,7 @@ private function doInsert($data, $type)

list($result, $executionTime) = $this->statement($queryObject->getSql(), $queryObject->getBindings());

$return = $result->rowCount() === 1 ? $this->pdo->lastInsertId() : null;
$return = $result->rowCount() === 1 ? $this->pdo->lastInsertId($sequence) : null;
} else {
// Its a batch insert
$return = array();
Expand All @@ -336,7 +336,7 @@ private function doInsert($data, $type)
$executionTime += $time;

if ($result->rowCount() === 1) {
$return[] = $this->pdo->lastInsertId();
$return[] = $this->pdo->lastInsertId($sequence);
}
}
}
Expand All @@ -351,29 +351,29 @@ private function doInsert($data, $type)
*
* @return array|string
*/
public function insert($data)
public function insert($data, $sequence = null)
{
return $this->doInsert($data, 'insert');
return $this->doInsert($data, 'insert', $sequence);
}

/**
* @param $data
*
* @return array|string
*/
public function insertIgnore($data)
public function insertIgnore($data, $sequence = null)
{
return $this->doInsert($data, 'insertignore');
return $this->doInsert($data, 'insertignore', $sequence);
}

/**
* @param $data
*
* @return array|string
*/
public function replace($data)
public function replace($data, $sequence = null)
{
return $this->doInsert($data, 'replace');
return $this->doInsert($data, 'replace', $sequence);
}

/**
Expand Down