Created attachment 144991 [details] Database table to demonstrate the error FireBird: Auto-Increase after copy table: Error inserting new data item. firebird_sdbc error: *violation of PRIMARY or UNIQUE KEY constraint "INTEG_9" on table "Letters" *Problematic key value is ("ID" = 2) caused by 'isc_dsql_execute' I have prepared the table "Letter" by copying it from another table. There are 4 lines in the table and I tried to register a fifth line. But ("ID" = 2) The ID value counts up from 1 and increases by 1 at each new attempt. After the table was copied, the reset value is zero. Therefore, the first entries fail because the key value is not allowed. But the restart value is incremented at each new attempt so that the value insertion succeeds when ID = 5 I have attached the file: Autoincrument error. Use it to see who the error behaves. Do the following: ' Copy "Letters" to Letters4. (Definition and data) Open Letter4 and try adding a new letter. It gives the above error message. Repeat the experiment until fifth succession succeeds. Delete the fifth line again. Delete Letters4 Kopier "Letters" til Letters4. (Definition og data) Kopier "Letters2" til letters4 (tilknyt kun data). Open Letters4 and try to insert a new letter. It gives the above error message. Repeat the experiment until it succeeds in the ninth time. The error can be corrected with: go to Tools> SQL and type in alter table TABLE_NAME change FIELD_NAME restart with 8; “alter table "Letters4" alter "ID" restart with 8;” However, I think updating should work immediately after copying. Delete Letters4 and Repeat. Copy "Letters" to Letters4. (Definition and data) Copy "Letters3" to letters4 (attach only data). Try to insert a new letter X, for example. It provides the above error message. Repeat the experiment until the thirteenth time succeeds. It only succeeded when an "X" comes in the letter field. The table now shows 5 times ID = 12. The one ID-12 is right the four others are wrong. I can not figure out why This view does not reflect the true table. Therefore close the table and open it again. The four fake 12's are now filled with the correct ID key figures. Those who were not already filled in. We could have removed the error in the same way as in the previous example, but this reveals another error or maybe the actual error. Regarding the 12 numbers. In the update we show that an entry is attempted to insert a line with ID = 12, There must be a variable that sets the correct number for (12 + 1) and this variable Must be inserted in ID that is the primary key. But the variable will not be set. It is only increased by 1 in relation to its previous value.
(In reply to Eigil Wiwe from comment #0) > Do the following: ' > > Copy "Letters" to Letters4. (Definition and data) > Open Letter4 and try adding a new letter. It gives the above error message. > Repeat the experiment until fifth succession succeeds. > Delete the fifth line again. > Delete Letters4 > Confirming with Version: 6.1.1.2 Build ID: 5d19a1bfa650b796764388cd8b33a5af1f5baa1b Threads CPU : 8; OS : Mac OS X 10.13.6; UI Render : par défaut; Locale : fr-FR (fr_FR.UTF-8); Calc: group threaded
So, it would appear that the code which manages the ID generator doesn't get the correct count, and causes the subsequent insertion errors.
Function isAutoIncrement returns a sal_bool value (sal_True or sal_False), see https://opengrok.libreoffice.org/xref/core/connectivity/source/drivers/firebird/ResultSetMetaData.cxx#186 According to https://github.com/FirebirdSQL/firebird/blob/master/doc/sql.extensions/README.identity_columns.txt, each identity column is associated with a generator (RDB$GENERATOR_NAME). This generator provide s a number and stores it. But it seems no mechanism exists in copy process to retrieve its state (or missed it). Still with this same doc, notice too that the test lines 206/207 is wrong 206 if(iType == 1) // IDENTITY 207 return true; it should be: 206 if(iType == 0 || iType == 1) // IDENTITY 207 return true; Since 0 is for GENERATED ALWAYS (you can't override the identiy column in Insert statements - insert/update/...) and 1 for GENERATED BY DEFAULT Now perhaps it's because construct method https://opengrok.libreoffice.org/xref/core/connectivity/source/drivers/firebird/Column.cxx#28 uses "GENERATED BY DEFAULT AS IDENTITY" but it's another story.
Dear Eigil Wiwe, To make sure we're focusing on the bugs that affect our users today, LibreOffice QA is asking bug reporters and confirmers to retest open, confirmed bugs which have not been touched for over a year. There have been thousands of bug fixes and commits since anyone checked on this bug report. During that time, it's possible that the bug has been fixed, or the details of the problem have changed. We'd really appreciate your help in getting confirmation that the bug is still present. If you have time, please do the following: Test to see if the bug is still present with the latest version of LibreOffice from https://www.libreoffice.org/download/ If the bug is present, please leave a comment that includes the information from Help - About LibreOffice. If the bug is NOT present, please set the bug's Status field to RESOLVED-WORKSFORME and leave a comment that includes the information from Help - About LibreOffice. Please DO NOT Update the version field Reply via email (please reply directly on the bug tracker) Set the bug's Status field to RESOLVED - FIXED (this status has a particular meaning that is not appropriate in this case) If you want to do more to help you can test to see if your issue is a REGRESSION. To do so: 1. Download and install oldest version of LibreOffice (usually 3.3 unless your bug pertains to a feature added after 3.3) from https://downloadarchive.documentfoundation.org/libreoffice/old/ 2. Test your bug 3. Leave a comment with your results. 4a. If the bug was present with 3.3 - set version to 'inherited from OOo'; 4b. If the bug was not present in 3.3 - add 'regression' to keyword Feel free to come ask questions or to say hello in our QA chat: https://kiwiirc.com/nextclient/irc.freenode.net/#libreoffice-qa Thank you for helping us make LibreOffice even better for everyone! Warm Regards, QA Team MassPing-UntouchedBug
Oleksii Makhotin committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/2a8e120db1c3175ff937cdbe6d0ade23dc380c01 tdf#119962 Fix autoincrement for copied table It will be available in 7.2.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.