I'm updated Drupal 7.10 to 7.12 with SQLite database, and error message:
PDOException: SQLSTATE[23000]: Integrity constraint violation: 19 PRIMARY KEY must be unique: UPDATE {sequences} SET value = GREATEST(value, :existing_id) + 1; Array ( [:existing_id] => 0 ) in db_next_id()
Update is not success.
Issue fork drupal-1425794
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #1
chx CreditAttribution: chx commentedhttp://api.drupal.org/api/drupal/includes--database--sqlite--database.in...
shouldn't
unset($args);
beunset($args[$k]);
???? Clearly this loop is about nuking NULLs.Comment #2
nevergone CreditAttribution: nevergone commentedDrupal 7.10 SQLite sequences dump
Comment #3
lotyrin CreditAttribution: lotyrin commentedI'm with chx in #1. I can't imagine that loop is acting as intended there.
I don't have an SQLite install to run tests against, but here's a patch.
Comment #4
lotyrin CreditAttribution: lotyrin commentedComment #5
chx CreditAttribution: chx commentedActually Damien said that if any of the arguments of GREATEST is NULL the result is NULL which makes sense -- if you compare any ways anything to NULL the result will be NULL. So, 1, 2, NULL, compare 2 to NULL is NULL, then 1 to NULL, NULL. See. So the loop actually is correct.
Comment #6
lotyrin CreditAttribution: lotyrin commentedHmm. That is the SQL GREATEST behavior. But, doing it as implemented spits out a notice:
PHP Notice: Undefined variable: args in /home/ubuntu/drupal/core/includes/database/sqlite/database.inc on line 165
because $args got unset. Also, the way it flows makes this behavior seem like an error rather than intended. I'm changing this to an early return and adding a comment. This change also simplifies the logic.
Probably doesn't fix the issue here though, so leaving as needs work.
Comment #7
chx CreditAttribution: chx commentedComment -- good idea. Simplification -- even better idea. What about
Comment #8
Damien Tournoud CreditAttribution: Damien Tournoud commentedThe search needs to be strict:
That said,
in_array()
would be a tad more self-documenting:Comment #9
lotyrin CreditAttribution: lotyrin commentedImplemented second suggestion from #8, as well as decided that less verbose code means more verbose comment.
Comment #10
lotyrin CreditAttribution: lotyrin commentedGoing to see if I can reproduce and solve the actual issue here, since the ambiguous code this patch fixes doesn't seem to be the cause.
Comment #11
marcingy CreditAttribution: marcingy commentedpatch needs to be against d8 and as per #7 this should be normal.
Comment #12
marcingy CreditAttribution: marcingy commented-
Comment #13
marcingy CreditAttribution: marcingy commented-
Comment #14
lotyrin CreditAttribution: lotyrin commentednevergone, do you have a minimal case which reproduces this? I've done the following:
I'll be trying other things (creating content types, enabling more core modules), but so far I'm unable to reproduce.
Comment #15
lotyrin CreditAttribution: lotyrin commentedNothing to go on here, unassigning.
Comment #16
geek-merlin"hint": i have had good "success" seeing this error when enabling modules.
Comment #17
geek-merlinOK, hunted this down, it's all about db_next_id() and the sequences table (which contains ony one unique row "value")
look at #2! in our case the sequences table contains 2 entries (which i think should normally never happen).
of course sqlite update will freak out when next_id() sais:
as it is told to update *all* rows to the same value.
inserting "on conflict replace" here should do the trick.
Comment #18
geek-merlinso let's feed the bot with a test case that should fail.
Comment #19
geek-merlinComment #20
geek-merlinand the fix that hopefully works
Comment #21
geek-merlinupsala, forgot to change method name, so here's the stuff.
Comment #22
geek-merlinand - in case this all works - here's the straight d7 backport.
Comment #23
lotyrin CreditAttribution: lotyrin commentedWon't on conflict replace mean that we've gotten the same value twice (once when the duplicate entry was created, once when we get and resolve the conflict)?
Is it unavoidable that the duplicate sequence entry gets created on SQLite? Should we try to prevent that from happening somehow?
Other than that this seems good, we'll see what the bots say.
It (rightfully) doesn't include the changes from my patch, that should become a separate issue.
Comment #24
geek-merlinwhat? i must have been lacking sleep when first testing the sql...
hold on and sorry folks and bot for all that noise.
Comment #25
geek-merlini hope this is the last iteration. going to sleep now.
@lotyrin: tested this manually, also see here: http://www.sqlite.org/lang_conflict.html
EDIT: also here some historical findings where the code comes from:
* implemented generically by chx in #356074-94: Provide a sequences API
* moved to sqlite (the generic implementation was dropped) by Josh Waihi in #633678-47: Make sequence API work on non-MySQL databases
Comment #27
geek-merlinto interpret this:
* d7 patch MUST fail
the other patches must be tested in a sqlite environment
the tests in my d7 environment do what they should (fail unpatched, pass patched)
as soon as i can i will set up a d8 sqlite environment and run tests locally.
Comment #28
geek-merlinComment #37
andypostComment #41
mradcliffeTagging because the issue summary references Drupal 7, but we want to apply the fix to Drupal 9 first.
Comment #48
quietone CreditAttribution: quietone at PreviousNext commentedIs this still a problem?
There has been no work on this issue for 8 years. It was pointed out 4 years ago that a re-roll was needed and 2 years ago an issue summary was requested. There has been no reply to those comments.
Since we need more information to move forward with this issue, I am setting the status to Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
Thanks!
Comment #49
daffie CreditAttribution: daffie commentedI do not think this is still a problem. The sequences table has been deprecated in #2665216: Deprecate Drupal\Core\Database\Connection::nextId() and the {sequences} table and schema.
Comment #50
quietone CreditAttribution: quietone at PreviousNext commented@daffie, thank you!
Based on #49 I am closing this as outdated.