How can i pass intger to a rawquery in sqlite for android. Here its not taking g and s into query. Please guide.
int g, s;
Cursor cur3 = database2.rawQuery("select max(UnixTimeStamp) from Quote where EmoticonID=%d and SubCategoryID=%d" ,new String [] {g,s});
Android SQLiteDatabase rawQuery (String sql, String [] selectionArgs) Runs the provided SQL and returns a Cursor over the result set. public Cursor rawQuery (String sql, String[] selectionArgs) String sql - the SQL query. The SQL string must not be ; terminated
RawQuery methods must return a non-void type. If you want to execute a raw query that does not return any value, use RoomDatabase#query methods. RawQuery methods can only be used for read queries. For write queries, use RoomDatabase.getOpenHelper ().getWritableDatabase () .
On the other hand, RawQuery serves as an escape hatch where you can build your own SQL query at runtime but still use Room to convert it into objects. RawQuery methods must return a non-void type. If you want to execute a raw query that does not return any value, use RoomDatabase#query methods.
RawQuery methods can return observable types but you need to specify which tables are accessed in the query using the observedEntities () field in the annotation.
All parameter places should be designated with ?. The parameters to the query are always string nontheless, so nothing special about the integers. This should work for you:
Cursor cur3 = database2.rawQuery("select max(UnixTimeStamp) from Quote where EmoticonID=? and SubCategoryID=?" ,new String [] {String.valueOf(g),String.valueOf(s)});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With