question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SQLite transactions do not work.

See original GitHub issue

When 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:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ghostcommented, Jun 12, 2020

@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#L3

ROLLBACK is defined here: https://github.com/nolanlawson/node-websql/blob/master/lib/websql/WebSQLDatabase.js#L10

I think maybe this should be documented/added to the Expo test cases.

1reaction
viktor-podziguncommented, Jun 12, 2020

@enzomd it works for me, as per spec here to rollback transaction you should either do not specify error handler (null) or return true from it:

tx.executeSql("...", [], null, null)
//or
tx.executeSql("...", [], null, (tx, error) => {
  return true //rollback
})
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found