-
Notifications
You must be signed in to change notification settings - Fork 522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
executeSql
silently fails on parameterised list value
#410
Comments
Ok, looks like I've found the real bug. Let's say I have table SELECT COUNT(tasks.id), TYPEOF(COUNT(tasks.id)) FROM tasks;
# 3 | integer Now I want to compare count value with some literal SELECT COUNT(tasks.id) == 3 FROM tasks;
# 1
SELECT COUNT(tasks.id) == 3.0 FROM tasks;
# 1
SELECT COUNT(tasks.id) == "3" FROM tasks;
# 0 No type conversion is applied between string and integer in this context. Both
no any type conversion is happening and we compare type INTEGER with TEXT Then according to 4.1. Sort Order
which means comparison SELECT COUNT(tasks.id) < "3" FROM tasks;
# 1
SELECT COUNT(tasks.id) >= "3" FROM tasks;
# 0 If this expression is applied somewhere in WHERE or HAVING COUNT(tasks.id) == "1" then it means you will always get empty list of results. This is a whole realm of possible bugs and very strange noone came across with this. Bug is in executeSqlStatementQuery function params[j] = SQLitePluginConverter.getString(queryParams, j, ""); where all parameters are converted into strings. I suggest that Android's rawQuery function wrap strings with backtics (as strings should be wrapped to distinguish them between integers) or even worse it only allows to bind strings for prepared statements (https://www.sqlite.org/c3ref/bind_blob.html)). |
I've tested and now it works! // params[j] = SQLitePluginConverter.getString(queryParams, j, "");
params[j] = SQLitePluginConverter.get(queryParams, j, ""); but I need to mention I'm using my own fork https://www.npmjs.com/package/@breeffy/mobbly public Cursor rawQuery(String sql, Object[] selectionArgs) {
return rawQueryWithFactory(null, sql, selectionArgs, null, null);
} while on Android documentation public Cursor rawQuery (String sql, String[] selectionArgs) |
The other possible way to fix this (using Android API, where only String[] is available) is to cast string into appropriate type directly. SELECT 3 == CAST("3" as integer);
# 1 |
Expected Behavior
Here's my schema:
Here's a statement that works in the sqlite3 CLI:
Now, I want to run this query in my Android react native app. If I do this:
then it works. However, if I do this (which is what I'm trying to achieve):
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
inSQLitePluginTransaction.prototype.addStatement
, because you'll coerce my argument list to a string so we end up withSQL
that looks like this: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
Debug logs
No logging output is given. I have called
SQLite.DEBUG(true)
, and still don't get any output.The text was updated successfully, but these errors were encountered: