react-native-sqlite-storage icon indicating copy to clipboard operation
react-native-sqlite-storage copied to clipboard

Turn javascript arrays into SQL lists

Open iamleeg opened this issue 5 years ago • 6 comments

Fixes #410.

iamleeg avatar Feb 10 '20 12:02 iamleeg

@iamleeg From what I've understood - sql statement and parameters (which should substitude "?" or similar symbols) goes directly into NativeModule (native part of react-native-sqlite-storage).

So I think this fix should be there, on native side - that's where error happens, not inside javascript.

likern avatar Feb 24 '20 20:02 likern

So it looks like this is not a correct fix.

likern avatar Feb 24 '20 20:02 likern

@likern that's not quite correct. If you look at the rest of the function I changed, it's responsible for turning JS objects into strings that can be handled in the native module. Before the change, it got arrays wrong, because it just stringified them. Now, it gets them right.

iamleeg avatar Feb 25 '20 09:02 iamleeg

But what I've seen from the code it puts parameters into array which later in passed to Native part. So it is not stringified in JavaScript. Convertion from array to string happens somewhere in Java.

likern avatar Feb 25 '20 09:02 likern

@iamleeg did you test you fix on iOS/Android and native Android ?

andpor avatar Apr 13 '20 19:04 andpor

@iamleeg 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])

if selected_roles will be a string s = "(1,2,3,4)"

then your query would have to become 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])

correct? It is either we generate a string with surrounding () or we generate a comma separated list instead s="1,2,3,4" and then the query would be 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])

I think my preference would be to generate a comma separated list only without creating artificial () which are really a function of SQL syntax and can vary....

What do you think ?

andpor avatar Apr 13 '20 19:04 andpor