capacitor-community / sqlite

Community plugin for native & electron SQLite databases
MIT License
426 stars 104 forks source link

ExecuteTransaction with values throws exception for statements performing no actual changes #544

Closed rastafan closed 2 weeks ago

rastafan commented 3 weeks ago

Hi,

i noticed that executing statements such as DELETE or UPDATE which results in no rows changed, causes the plugin to throw an exception.

As an example, this is the case of DELETE operations on empty tables, or using conditions that results in no rows deleted.

This happens when using executeTransaction and passing parameters along with the statement:

this._db.executeTransaction([
    {
        statement: 'DELETE FROM some_table WHERE some_column = ?',
        values: [2]
     },
    {
        statement: 'DELETE FROM some_other_table WHERE some_other_column = ?',
        values: [3]
     }
])

this causes the plugin to use the run method internally. The returned number of changes is 0, which seems right, but 0 is treated as an error condition and an exception is thrown. This behavior is different from the "execute" part of this code, which is uses when no values are passed, and does not treat the "0 changes" condition as an error state.

The piece of internal code i'm referring to is this one: LINK

I would make a PR for this, but i'm not able to understand if there is a condition where it returns changes=0 upon some sort of error.

If anyone can help me test it (or can test it in my place) please let me know, so i can make a PR for this.

Thank you very much.

jepiqueau commented 3 weeks ago

@rastafan which platform?

rastafan commented 3 weeks ago

tried only on web platform, still to test on android/ios

jepiqueau commented 3 weeks ago

@rastafan you right there is no reason to sent an error if changes is equal to 0. i will fix it in the next release

rastafan commented 3 weeks ago

Alright, thank you very much!!

jepiqueau commented 2 weeks ago

@rastafan fixed in v5.7.3-3.