-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix fetching last insert ID for sequences on SQL Server 8000 #2634
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
Fix fetching last insert ID for sequences on SQL Server #2634
Conversation
return parent::lastInsertId($name); | ||
} | ||
|
||
$sql = 'SELECT CONVERT(VARCHAR(MAX), current_value) FROM sys.sequences WHERE name = ?'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant? You mean I should inject it into prepare()
directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@@ -40,6 +40,22 @@ public function __construct($dsn, $user = null, $password = null, array $options | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
public function lastInsertId($name = null) | |||
{ | |||
if (null === $name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can a name be empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As in ''
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. What should we expect in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's why I asked. Probably needs a new issue though, where we validate that the passed in value is not empty or such.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ocramius the problem is the interface does not specify such case. Neither does PDO's interface. No exception, not non-string return value specified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then all ok: had to ask 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, not happy with the situation either but that's what it is right now :(
$stmt = $this->prepare($sql); | ||
$stmt->execute(array($name)); | ||
|
||
return $stmt->fetchColumn(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can current_value
ever be NULL
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given to the documentation no.
3e79791
to
5533854
Compare
Btw the Oracle test failure is obviously unrelated. That test in question seems fragile. Think I have encountered that one on Oracle sometime before. Need to have a look at that. |
Test failure fixed in #2635 |
…fix' into 2.5 Backport #2634 into 2.5.*
Backported to |
Fixes fetching last insert ID for sequences on both
sqlsrv
andpdo_sqlsrv
drivers. The implementation onsqlsrv
was wrong andpdo_sqlsrv
does not support this out of the box.The issue was revealed in #2617. See: