Skip to content

Commit 8e3b1bd

Browse files
committed
Added support for queries with parameters bound by type:
- Updated SQLCipher libraries
1 parent c822733 commit 8e3b1bd

5 files changed

Lines changed: 19 additions & 11 deletions

File tree

src/android/io/sqlc/SQLiteAndroidDatabase.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,24 @@ private void bindArgsToStatement(SQLiteStatement myStatement, JSONArray sqlArgs)
285285
}
286286
}
287287
}
288+
289+
private static Object[] getParamsFromJSON(JSONArray paramsAsJson) throws JSONException {
290+
Object[] params = new Object[paramsAsJson.length()];
291+
292+
for (int i = 0; i < paramsAsJson.length(); i++) {
293+
if (paramsAsJson.get(i) instanceof Float || paramsAsJson.get(i) instanceof Double) {
294+
params[i] = paramsAsJson.getDouble(i);
295+
} else if (paramsAsJson.get(i) instanceof Number) {
296+
params[i] = paramsAsJson.getLong(i);
297+
} else if (paramsAsJson.isNull(i)) {
298+
params[i] = null;
299+
} else {
300+
params[i] = paramsAsJson.getString(i);
301+
}
302+
}
303+
304+
return params;
305+
}
288306

289307
/**
290308
* Get rows results from query cursor.
@@ -299,17 +317,7 @@ private JSONObject executeSqlStatementQuery(SQLiteDatabase mydb,
299317

300318
Cursor cur = null;
301319
try {
302-
String[] params = null;
303-
304-
params = new String[paramsAsJson.length()];
305-
306-
for (int j = 0; j < paramsAsJson.length(); j++) {
307-
if (paramsAsJson.isNull(j))
308-
params[j] = "";
309-
else
310-
params[j] = paramsAsJson.getString(j);
311-
}
312-
320+
Object[] params = getParamsFromJSON(paramsAsJson);
313321
cur = mydb.rawQuery(query, params);
314322
} catch (Exception ex) {
315323
ex.printStackTrace();
1.83 MB
Binary file not shown.
1.96 MB
Binary file not shown.
-244 Bytes
Binary file not shown.
1.94 MB
Binary file not shown.

0 commit comments

Comments
 (0)