Commit 31c41ee0 authored by Marco Pivetta's avatar Marco Pivetta

Merge branch 'fix/#2634-last-insert-id-fetching-in-sql-server-syntax-fix' into 2.5

Backport #2634 into 2.5.*
parents 77b764ad 1ea99a2f
......@@ -40,6 +40,21 @@ class Connection extends PDOConnection implements \Doctrine\DBAL\Driver\Connecti
/**
* @override
*/
public function lastInsertId($name = null)
{
if (null === $name) {
return parent::lastInsertId($name);
}
$stmt = $this->prepare('SELECT CONVERT(VARCHAR(MAX), current_value) FROM sys.sequences WHERE name = ?');
$stmt->execute(array($name));
return $stmt->fetchColumn();
}
/**
* {@inheritDoc}
*/
public function quote($value, $type=\PDO::PARAM_STR)
{
$val = parent::quote($value, $type);
......
......@@ -130,9 +130,8 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection
public function lastInsertId($name = null)
{
if ($name !== null) {
$sql = "SELECT IDENT_CURRENT(".$this->quote($name).") AS LastInsertId";
$stmt = $this->prepare($sql);
$stmt->execute();
$stmt = $this->prepare('SELECT CONVERT(VARCHAR(MAX), current_value) FROM sys.sequences WHERE name = ?');
$stmt->execute(array($name));
return $stmt->fetchColumn();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment