SQLite transactions do not work.
See original GitHub issueWhen tx.executeSql(
x, [], onSuccess, onError);
is run inside a db.transaction(t, error, success)
, each statement runs as its own transaction.
The expo API does not issue any BEGIN TRANSACTION
or COMMIT TRANSACTION
statements.
https://www.sqlite.org/lang_transaction.html
This is misleading as the documentation does not mention this, and the API specifically mentions transaction
.
Here is a reproduction:
https://snack.expo.io/r1A-1yPw4
- A table is created, with a single row inserted.
- Inside the same transaction, a SQL syntax error is purposely thrown.
- What should happen: Transaction is rolled back, no changes applied to DB, transaction error callback called.
- What happens: The new table and row are written to disk, the transaction success callback is called.
Please can you update your documentation to mention that transactions are not supported.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:6 (2 by maintainers)
Top Results From Across the Web
sql - SQLite Transactions not working
But it's a transaction, if a query fails rest of the queries should not work. Nope, that's not how transactions work.
Read more >SQLite Forum: PROBLEM WITH TRANSACTION
Hello, I am trying to learn SQLite and I am taking an online course. ... END TRANSACTION; The transaction code doesn't work, what's...
Read more >SQLite Transaction Explained By Practical Examples
Learn how to deal with SQLite transactions by using the BEGIN TRANSACTION, COMMIT, and ROLLBACK statements to control transactions.
Read more >sqlite3 — DB-API 2.0 interface for SQLite databases
Call sqlite3.connect() to to create a connection to the database tutorial.db in the current working directory, implicitly creating it if it does not...
Read more >Transactions - Microsoft.Data.Sqlite
Transactions let you group multiple SQL statements into a single unit of work that is committed to the database as one atomic unit....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@viktor-podzigun I think you are right, I tested with returning
true
from the error handler and this rolled back the transaction. Thanks for posting the solution.Expo includes
node-websql
here: https://github.com/expo/expo/blob/master/packages/expo-sqlite/src/SQLite.ts#L3ROLLBACK
is defined here: https://github.com/nolanlawson/node-websql/blob/master/lib/websql/WebSQLDatabase.js#L10I think maybe this should be documented/added to the Expo test cases.
@enzomd it works for me, as per spec here to rollback transaction you should either do not specify error handler (
null
) or returntrue
from it: