Reputation: 3171
I am trying to write a select query from one single table in SQLite DB in my app where data exists.
This is the SQL.table has these columns - id(INTEGER), start_time(INTEGER), category(TEXT)
select category from tuuserid_pref where id = (select max(id) from tuuserid_pref
where start_time < '1242');
by the way I want to bind the value shown in 1242 which I have in an Integer variable.
I have written selects and inserts and updates without binding parameters and they work using db.execSQL and db.rawQuery functions but just cannot figure the binding parameters out.
Any help is much appreciated.
Upvotes: 2
Views: 2380
Reputation: 20645
You need to modify your select statement like so:
select category from tuuserid_pref where id =
(select max(id) from tuuserid_pref where start_time < ?);
Then use the following rawQuery
call:
rawQuery(String sql, String[] selectionArgs)
Pass your variable into the second parameter wrapped in a String []
, which should give you something like the following statement:
db.rawQuery(sqlStatement, new String[] { String.valueOf(myInt) });
http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html
Upvotes: 2