Menu

#697 [SQLite3] unrelated problem might prevents table rename

Git
closed-fixed
nobody
None
5
2019-08-21
2019-08-06
No

To probably workaround to place a new column at any position in a table while sqlite does not support that out of the box, Adminer copies a table to a new table with prefix 'adminer_' and then drops the original table and rename the new table to the original one.

In some cases that does not work and the temporary table name is kept. (btw. what happens with autoincrement values, foreign key constraints, triggers, ..?)

Here is a case where this could happen:

sqlite> .schema
CREATE TABLE IF NOT EXISTS "adminer_test" (
  "atext" text NULL,
  "anumber" integer NULL
);
CREATE TABLE IF NOT EXISTS "adminer_items" (
  "name" text NULL
);
CREATE VIEW "itemview" AS
select name from items;
sqlite> alter table adminer_test rename to test;
Error: error in view itemview: no such table: main.items
sqlite> 

The view 'itemview' is invalid because table items exists not anymore. That issue is unrelated to an attempt to rename another table.

Adminer does not catch that error and I wonder why there is a BEGIN; COMMIT; if the transaction fails in the middle of work, see screenshot. So transactions are not working? Or ROLLBACK missing?

1 Attachments

Discussion

  • Peter Liscovius

    Peter Liscovius - 2019-08-06

    and later

     
  • Jakub Vrána

    Jakub Vrána - 2019-08-21
    • status: open --> open-accepted
     
  • Jakub Vrána

    Jakub Vrána - 2019-08-21

    Thanks for the detailed repro steps, I can reproduce this. SQLite should error right at CREATE VIEW "itemview" AS select name from items and not later on an unrelated command. Anyway… The root cause is that the rename command fails but SQLite3::query() doesn't report this error (however, if the result is not used then it reports it!). This is probably caused by SQLite3::query() using sqlite3_prepare_v2 and sqlite3_step instead of sqlite3_exec.

    I'd probably need to change SQLite3::query() to SQLite3::exec() here.

     
    • Jakub Vrána

      Jakub Vrána - 2019-08-21

      SQLite3::query() doesn't report the error only if it's executed in one command BEGIN; command; COMMIT which is not the case with Adminer. Good.

       
  • Jakub Vrána

    Jakub Vrána - 2019-08-21
    • status: open-accepted --> closed-fixed
     
  • Jakub Vrána

    Jakub Vrána - 2019-08-21

    Foreign keys and triggers were already preserved, I've added preserving also auto increment values.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.