8000 Fix fetching last insert ID for sequences on SQL Server by deeky666 · Pull Request #2634 · doctrine/dbal · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Merged

Conversation

deeky666
Copy link
Member
@deeky666 deeky666 commented Feb 5, 2017

Fixes fetching last insert ID for sequences on both sqlsrv and pdo_sqlsrv drivers. The implementation on sqlsrv was wrong and pdo_sqlsrv does not support this out of the box.

The issue was revealed in #2617. See:

return parent::lastInsertId($name);
}

$sql = 'SELECT CONVERT(VARCHAR(MAX), current_value) FROM sys.sequences WHERE name = ?';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable redundant

Copy link
Member Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct

Copy link
Member Author

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) {
Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in ''

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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 👍

Copy link
Member Author

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();
Copy link
Member

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?

Copy link
Member Author

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.

@deeky666 deeky666 force-pushed the fix-sqlserver-sequence-last-insert-id branch from 3e79791 to 5533854 Compare February 6, 2017 00:09
@deeky666
Copy link
Member Author
deeky666 commented Feb 6, 2017

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.

8000

@deeky666
Copy link
Member Author
deeky666 commented Feb 6, 2017

Test failure fixed in #2635

@Ocramius Ocramius self-assigned this Feb 6, 2017
@Ocramius Ocramius merged commit cc1e9a9 into doctrine:master Feb 6, 2017
Ocramius added a commit that referenced this pull request Feb 6, 2017
@Ocramius
Copy link
Member
Ocramius commented Feb 6, 2017

Backported to 2.5 via 31c41ee

6EFE
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0