1

I am new to Android Studio and android development, I'm having problems passing in multiple parameters into sqlite using a cursor I have the following:

Cursor cursor = DB.rawQuery("select _id, BookingType as bookingType from " + table + " where " + SqLiteTableData.TableStructure.KEY_BOOKING_DATE+" = ?  AND  " + SqLiteTableData.TableStructure.KEY_BOOKING_TIME+ " = ? " , new String[]{a, b });

which in the debugger displays the following:

SQLiteDirectCursorDriver: select _id, BookingType as bookingType from Bookings where BookingDate = ?  AND  BookingTime = ?

The parameters are not been passed

I have spent ages on this and looked at other posts such as How to pass two or more selection argument in "query" method

android sqlite query with multiple where

But cannot get it to work

Any help appreciated

Community
  • 1
  • 1
George Phillipson
  • 830
  • 11
  • 39

2 Answers2

0

Your code is correct. The parameters are passed correctly.

The debugger does not show parameter values because they are never merged into the SQL command text. The database handles the parameters at a later stage.

CL.
  • 173,858
  • 17
  • 217
  • 259
0

I suggest you could use the query function instead of rawQuery since it was much easy to handle.

In your case, your query function would be:

    Cursor cursor = DB.query(table, "_id, BookingType as bookingType", SqLiteTableData.TableStructure.KEY_BOOKING_DATE+"= ? AND"SqLiteTableData.TableStructure.KEY_BOOKING_TIME+"= ?", new String[]{a,b},null, null);
Johnny Cheuk
  • 237
  • 2
  • 15