I am currently using the android-sqlite-asset-helper to load a SQLite databse I have created. At the moment I can't get the following query to work:
SELECT ColumnX FROM TABLE WHERE L6 > 381 Limit 1;
This query is built using the following code:
SQLiteDatabase db = getReadableDatabase();
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
String[] args = {arg1, arg2};
qb.setTables(TABLENAME);
Cursor c = qb.query(db, new String[] {"ColumnX"}, "? > ?", args, null, null, null, "1");
Here is a snippet of my data:
For example if ColumnX = Nom
arg1 = L8
and arg2 = 380
then I would expect to get 25 but the cursor always returns with the first element of the Nom column.
Am I missing something fundamental here?
I'm guessing that your columns are of type integer. When you're substituting ? with arg2 it is transformed to a string.
So in the end you're calling:
SELECT ColumnX FROM TABLE WHERE L6 > '381' Limit 1;
To fix that, insert the integer manually:
Cursor c = qb.query(db,
new String[] {"Nom"},
"? > " + arg2,
new String[] { arg1 },
null, null, null, "1");
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加