Skip to content

executeSql silently fails on parameterised list value #410

Open
@iamleeg

Description

@iamleeg

Expected Behavior

Here's my schema:

sqlite> .schema
CREATE TABLE risk (id integer primary key, description varchar, weight integer, severity integer, likelihood integer, type_1 varchar, type_2 varchar, approach_time varchar, approach_type varchar, stage_1 varchar, stage_2 varchar);
CREATE TABLE role (id integer primary key, name varchar, unique(name));
CREATE TABLE skill (id integer primary key, name varchar, unique(name));
CREATE TABLE method (id integer primary key, name varchar, unique(name));
CREATE TABLE risk_role_skill (id integer primary key, risk_id integer, role_id integer, skill_id integer);
CREATE TABLE risk_method (id integer primary key, risk_id integer, method_id integer);

Here's a statement that works in the sqlite3 CLI:

sqlite> select max(weight) from risk inner join risk_role_skill on risk.id = risk_role_skill.risk_id and risk_role_skill.role_id in (1,2,3,4) where stage_2 like
 'Stage0 - Appraisal';
4

Now, I want to run this query in my Android react native app. If I do this:

db.executeSql('select stage_2, max(weight) from risk inner join risk_role_skill on risk.id = risk_role_skill.risk_id and risk_role_skill.role_id in (1,2,3) where stage_2 like ?', [stage])

then it works. However, if I do this (which is what I'm trying to achieve):

db.executeSql('select stage_2, max(weight) from risk inner join risk_role_skill on risk.id = risk_role_skill.risk_id and risk_role_skill.role_id in (?) where stage_2 like ?', [selected_roles, stage])

then the library does nothing. It doesn't call either success or error callback, it just doesn't run the statement. The library doesn't produce any debug logging for this situation, either. I have alternatively tried removing the parentheses around the first parameter (i.e. ...role_id in ? where stage_2..., with no change in behavior.

My expectation is that it's possible to pass a list as a parameter to an SQL statement, and that if I get the syntax wrong, the library will produce an error.

Current Behavior

See the description above: TL;DR the current behavior is no behavior.

Possible Solution

I think the issue is at sqlite.core.js:506 in SQLitePluginTransaction.prototype.addStatement, because you'll coerce my argument list to a string so we end up with SQL that looks like this:

...and role_id in [1,2,3]...

which is not valid. For an array parameter, emit an opening (, then stringify each element, then a closing ).

Steps to Reproduce (for bugs)

See the database schema and example queries above.

Context

I know that my query is correct because I have executed it in the sqlite3 CLI. The impact of this issue is that I can't implement a feature of my risk-management app which requires me to visualize the highest risk level at each stage in a particular project type.

Your Environment

  • React Native SQLite Storage Version used: 4.1.0
  • React Native version used: 0.61.5
  • Operating System and version (simulator or device): Android Simulator API level 29
  • IDE used: VS Code

Debug logs

No logging output is given. I have called SQLite.DEBUG(true), and still don't get any output.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions