react-native-sqlite-storage
react-native-sqlite-storage copied to clipboard
Turn javascript arrays into SQL lists
Fixes #410.
@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.
So it looks like this is not a correct fix.
@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.
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.
@iamleeg did you test you fix on iOS/Android and native Android ?
@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 ?