SQLite - local Transactions are ignored. How to fix Order of Operation?
Added by Christian Meyer 22 days ago
Hi,
I want to update a table in sqlite and used Session::execute(statement).run()
as well as Transaction::connection()->executeSQL(statement)
this is the error that follows a call to flush()
:
Dbo.backend.Sqlite3: alter table "tablehistory"
add "sqlupdate_fail" text not null DEFAULT '';
alter table "tablehistory"
add "sqlupdate_plan" text not null DEFAULT '';
Dbo.backend.Sqlite3: rollback transaction
Sqlite3: insert into "tablehistory" ("version", "sqlcreate", "sqlupdate", "sqlupdate_plan", "sqlupdate_fail", "datetime") values (?, ?, ?, ?, ?, ?): table tablehistory has no column named sqlupdate_plan
I am stumped as to why this insert into
is executed and added to the transaction that should already be closed.
Further investigation shows that there is a transaction open, when the updateFunction is called.
Within the UpdateFunction I open several Transactions in limited Scope to enable commits in between.
I updated my ConnectionPool
and increased the number of connections
available, but apparently SQLite only supports 1 - ONE
open Transaction
.
After the "successful" execution of alter table, I add an Item of said Table to the Database.
I thought this is handled within it's own Transaction
and therefore the insert should work, even if it's within the same transaction.
When I realized, that I added the Item before and then altered it, I moved the addition to the Session until after the alter statements, but the same error persists.
Not sure how to alter and add in the same go, with the looming Transaction from the calling function.
calling .commit()
on the local transactions did nothing.
Tested in Wt-4.10.4 and 4.11.4 with the same results.
Updating Other Tables usually worked with no issues, as these did not add items as well.
Cheers
Replies (3)
[[SOLEVD]]: SQLite - local Transactions are ignored. How to fix Order of Operation? - Added by Christian Meyer 19 days ago
Had to Scope the calling transaction and ran into other troubles
totally unrelated to SQLite or Dbo
But I will keep that limitation in mind
SQLite - Multiple Alter Statements in Single Transaction fail - Added by Christian Meyer 18 days ago
Short update for anyone looking for it
Alter statements in SQLite can only be run one at a time and in its own transaction.
even though sqlite states that multiple alter statements can be run in the same transaction, this is apparently not possible with wt....
at least with
- tl.connection()->executeSql(statement);
- execute(statement).run();
I multiple statements are run like this, only the first statement will execute. (Delimited by ;
)
RE: SQLite - local Transactions are ignored. How to fix Order of Operation? - Added by Matthias Van Ceulebroeck 16 days ago
Hey Christian,
I think the Sqlite3 backend of Wt is custom code, so I can imagine it contains a bug or two.
I'll verify your approach, and create a ticket if necessary.