Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SQLite rawquery parameters

Tags:

android

sqlite

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});
like image 583
Programmer Avatar asked Feb 18 '12 12:02

Programmer


People also ask

What is rawquery in Android SQLite?

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

How do I use rawquery methods?

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 () .

What is the difference between roomdatabase and rawquery?

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.

Is it possible to return observable data from rawquery?

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.


1 Answers

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)});
like image 197
Boris Strandjev Avatar answered Oct 28 '22 12:10

Boris Strandjev