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

[FIX] - Fix PHP original PDO_PGSQL::lastInsertId #2328

Closed
wants to merge 1 commit into from

Conversation

phackwer
Copy link

Fix PHP original PDO_PGSQL::lastInsertId which sometimes complains

about a sequence that has not been used it on the transaction (error):

Object not in prerequisite state: 7 ERROR: currval of sequence sequence_name is not yet defined in this session

…lains

about a sequence that has not been used it on the transaction (error):

Object not in prerequisite state: 7 ERROR:  currval of sequence sequence_name is not yet defined in this session
@Ocramius
Copy link
Member

@deeky666 is 2.4 still maintained?

*
* @return \Doctrine\DBAL\Driver\PDOPgSql\Exception
*/
static public function fromErrorInfo($error)
Copy link
Member

Choose a reason for hiding this comment

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

unused?

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I see that you use the constructor, not this named constructor...

@Ocramius
Copy link
Member

@phackwer what kind of situation triggers the problem? Can you reproduce it in a test case?

@phackwer
Copy link
Author

Marco,

How to trigger:
When you try to execute a "lastInsertId" on any sequence that has not yet executed an insert, you get this error, since currval not avaliable (this is how you trigger it by forcing the error). Somewhere on Doctrine code, there may be a bad call on lastInsertId (I don't know where exactly), making it to be called before the insert is actually made on the database. I just couldn't backtrace it to force the error on Doctrine code.

This is a PHP bug (which I will also and still send the fix - here's the cause (https://github.com/php/php-src/blob/master/ext/pdo_pgsql/pgsql_driver.c#L375), and this is a Doctrine workaround to allow Doctrine to still work with earlier PHP versions, since bugfix will be avaliable only on 5.6.x and 7.x.

Answering about branch 2.4, I don't know if it's still maintened, but you (specifically you) have made the 2.4.5 release earlier these year and it is marked as the latest release. Also this is the one we are using here in Brazil with some government clients that insists on force us to make code compatible with PHP 5.3.3, just because this is the one supported by RedHat "Enterprice" Linux 6, which is the one they have support contracts. Maybe I should upgrade to 2.5.x, but still, this fix should be made.

About the PHP bug, you can google it just to find out that this is a big that affects thousands of people around the world. The correct solution PostgreSQL solution since version 8.1 is to call the LASTVAL() function instead of using the currval old option.

Releases (latest is yours and on 2.4 branch):
https://github.com/doctrine/dbal/releases/tag/v2.4.5

PHP Bug:
https://www.google.com.br/search?num=50&newwindow=1&espv=2&q=Object+not+in+prerequisite+state+currval+of+sequence&oq=Object+not+in+prerequisite+state+currval+of+sequence&gs_l=serp.3..0i7i30.4410.4410.0.4643.1.1.0.0.0.0.121.121.0j1.1.0....0...1c.1.64.serp..0.1.120.RBB9OTxPd4g

@phackwer
Copy link
Author

About tests: I will try to write them. So far, the bug seems a critical one and fixes doctrine for thousands of systems.

@phackwer
Copy link
Author

As you can see here, also phalcon has this problem, since it is PHP's bug:

phalcon/cphalcon#1134

@phackwer
Copy link
Author

Any idea of when will your database be avaliable again?

This build error has no relation to my code:

https://travis-ci.org/doctrine/dbal/jobs/112441592#L319

@Ocramius
Copy link
Member

Ah yes, we do not support php <5.4 anymore. Unless there is a security issue, this patch will only land in 2.5

@phackwer
Copy link
Author

phackwer commented Mar 1, 2016

:-(

Can't you at least make a final release to overwrite this PHP problem for those who must use 2.4.x?

Just this last pull request? XD

@daniloesser
Copy link

I've got the same situation here.
+1 vote for this pull request.

@fabioluciano
Copy link

+1 vote on thia pull request.

Same issue here.

@gustavomagalhaess
Copy link

+1 vote for this pull request.

@Ocramius
Copy link
Member

Ocramius commented Mar 1, 2016

Can't you at least make a final release to overwrite this PHP problem for those who must use 2.4.x?

This is not a security issue. Don't think it's gonna happen. The merge will happen for 2.5.x. As you pointed out to me, for 2.4.x, the workaround is to simply use your own custom platform.

@ the other 3 that "upvoted" - upvoting has nothing to do with release schedules, sorry :-\

@celorodovalho
Copy link

I've got the same situation here.
+1 vote for this pull request.

@phackwer
Copy link
Author

This has been fixed directly on PHP source by myself.

php/php-src#2014

@phackwer phackwer closed this Jul 27, 2016
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 20, 2022
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.

None yet

6 participants