capacitor-community / sqlite

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

SQL query is converted to be compatible with SQL92 regardless of argument value of isSQL92 in query method when values argument is an empty array #519

Closed ygarg465 closed 2 months ago

ygarg465 commented 2 months ago

Describe the bug query method of the library is converting the SQL query to be compatible with SQL92 whether or not isSQL92 parameter is true or false. This occurs when the query method has values as an empty array.

Desktop (please complete the following information):

Additional context

@jepiqueau I think the problem occurs due to this code

 async query(
    statement: string,
    values?: any[],
    isSQL92 = true,
  ): Promise<DBSQLiteValues> {
    let res: any;
    try {
      if (values && values.length > 0) {
        res = await this.sqlite.query({
          database: this.dbName,
          statement: statement,
          values: values,
          readonly: this.readonly,
          isSql92: true, // we check for this value further down in the code
        });
      } else {
        res = await this.sqlite.query({
          database: this.dbName,
          statement: statement,
          values: [],
          readonly: this.readonly,
          isSQL92: isSQL92, // but this is invalid I think
        });
      }

      // reorder rows for ios
      res = await this.reorderRows(res);
      return Promise.resolve(res);
    } catch (err) {
      return Promise.reject(err);
    }
  }
jepiqueau commented 2 months ago

@ygarg465 i do not understand why you said is wrong.

ygarg465 commented 2 months ago

@jepiqueau The problem is the object being passed to the the.sqlite.query method, read the comment in the code block.

The isSql92 and isSQL92 are two different properties.

jepiqueau commented 2 months ago

@ygarg465 okn thanks it is isSql92 which is wrong so i will fix this in the next release

ygarg465 commented 2 months ago

@jepiqueau can you release the stable version of 5.6.1, I am using electric-sql which uses this library and there is a peer dependency conflict with that if I use version 5.6.1-4 that contains the fix of issue#518.

jepiqueau commented 2 months ago

@ygarg465 v5.6.1 has been released. After test on your side can you close the issue

ygarg465 commented 2 months ago

@jepiqueau Yes this works perfectly fine and Thanks for releasing it this fast :)

jepiqueau commented 2 months ago

@ygarg465 👍