Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No rollback on failed transactions #566

Open
laurent22 opened this issue Jan 3, 2024 · 1 comment
Open

No rollback on failed transactions #566

laurent22 opened this issue Jan 3, 2024 · 1 comment

Comments

@laurent22
Copy link

I'm trying to get transactions to work using this library, but some reason rollback is not working. My expectation is that if any statement in the transaction failed, the whole transaction should be rollbacked. Instead it appears to commit all statements except the failed one.

Below is my test code. Any idea what might be the issue?

const queries = [
	{
		sql: `DROP TABLE IF EXISTS testing`,
		params: [],
	},
	{
		sql: `
			CREATE TABLE testing (
				id TEXT PRIMARY KEY,
				title TEXT NOT NULL DEFAULT ""
			)`,
		params: [],
	},
	{
		sql: `INSERT INTO testing (id, title) VALUES (?, ?)`,
		params: ["1", "one"],
	},
	{
		sql: `INSERT INTO doesnotexist (id, title) VALUES (?, ?)`,
		params: ["2", "two"],
	},
]

try {
	await db.transaction(tx => {
		for (const query of queries) {
			tx.executeSql(query.sql, query.params);
		}
	});
} catch (error) {
	console.error('SQL error:', error);
}

const result = await db.executeSql('SELECT * FROM testing');

// Displays "["1", "one"]", which shows that the transaction was not rollbacked:

console.info('RESULT:', result[0].rows.item(0));
@LaGregance
Copy link

LaGregance commented Jun 22, 2024

Hi,

I just tested and I confirm transaction are not rollback on Android (it work fine on iOS).

I've created a fork of this repository that bring multiple things:

  • Fix this issue
  • Add UUID support
  • Update SQLite version to 3.43.1 (release on 2023-09-11)
  • Bring same version of SQLite for iOS & Android, independent of OS version (this mean SQLite is also compiled for iOS)

I hope that this fork will become the new reference for using SQLite with react native and will be regularly updated.
Do you have any idea of how to address this issue ? Or, alternatively, a direction in which to look for a solution (in which file it happens, for example) ? If possible I would be glad to add a fix in the fork.

The fork: https://www.npmjs.com/package/@boltcode/react-native-sqlite-storage

If you want to understand what I've done in this fork, there is a documentation about it.

Have a good day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants