OP-Engineering / op-sqlite

Fastest SQLite library for react-native by @ospfranco
MIT License
593 stars 41 forks source link

Warning during commit or rollback of the transaction - "No transaction is active" #164

Closed maksym-kyryliuk closed 1 month ago

maksym-kyryliuk commented 1 month ago

Describe the bug After updating to the 9.2.2, every time I manually commit or roll back the transaction I am getting a warning:

image

To reproduce the issue is enough to use code from documentation:

await db.transaction((tx) => {
  const { status } = await tx.execute(
    'UPDATE sometable SET somecolumn = ? where somekey = ?',
    [0, 1]
  );

  await tx.rollback();
});
await db.transaction((tx) => {
  const { status } = await tx.execute(
    'UPDATE sometable SET somecolumn = ? where somekey = ?',
    [0, 1]
  );

  await tx.commit();
});
await db.transaction(async tx => {
  try {
    const {status} = await tx.execute(
      "UPDATE sometable SET somecolumn = ? where somekey = ?",
    [0, 1]
  );

    throw new Error('Random Error!');
  } catch (error) {
    tx.rollback();
  }
});

My configuration:

  "op-sqlite": {
    "sqlcipher": false,
    "crsqlite": false,
    "performanceMode": "2",
    "sqliteFlags": "-DSQLITE_DQS=1",
    "libsql": false,
    "iosSqlite": false,
    "fts5": true
  }
ospfranco commented 1 month ago

Can you create a reproducible example? All the tests are passing

maksym-kyryliuk commented 1 month ago

@ospfranco Sure, here is the link to the example.

Load the app, and press the "Go to list" button. On the next screen, you will see 2 buttons:

  1. Add category with records - will start a transaction and call tx.commit() in the end
  2. Test error - will start a transaction, throw an error, and in the catch will call tx.rollback().

Both of them leads to the warning below: image

maksym-kyryliuk commented 1 month ago

Despite the warning above, the logic seems to work correctly for both commit and rollback. But this warning appears every time now for these cases.

Upd: Updated the title and description of the issue to reflect it.

maksym-kyryliuk commented 1 month ago

Also there are two logs seems wasn't removed from the release:

 LOG  BEFORE FLUSH
 LOG  AFER FLUSH

Link: https://github.com/OP-Engineering/op-sqlite/blob/main/src/index.ts#L352

ospfranco commented 1 month ago

You have to await the commit or the rollback. All sql operations are now async. After changing no warning is shown.

OSP 000431