enter code hereI am trying to write a query to extract all rows in my Android SQLite database table where the location reference = "a string". I am using the following code in my database helper class:
public Cursor fetchComponentsForLocation(String locationRef) {
Cursor mCursor =
rmDb.query(true, LOCATIONS_TABLE, new String[] {
LOCATION_ID, RUN_LINK, AREA_LINK, INSPECTION_LINK, LOCATION_REF, RACKING_SYSTEM, COMPONENT, POSITION, RISK, ACTION_REQUIRED, NOTES_GENERAL, MANUFACTURER, TEXT1, TEXT2, TEXT3, TEXT4, NOTES_SPEC},
LOCATION_REF + "=" + locationRef, null,
null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
And I call it in my activity as follows:
// Get a Cursor for the list items
Cursor listComponentCursor = rmDbHelper.fetchComponentsForLocation(locationRef);
startManagingCursor(listComponentCursor);
// set the custom list adapter
setListAdapter(new MyListAdapter(this, listComponentCursor));
Which then gets used in my ListAdapter to fill my list view. Now in my other activities, when I am fetching rows based on the id (i.e. a long), this code works fine. When I try it with String I get the following error:
Caused by: android.database.sqlite.SQLiteException: **no such column: g:** , while compiling: SELECT DISTINCT _id, run_link, area_link, inspection_link, location_reference, racking_system, component, position, risk, action_required, notes_general, manufacturer, text1, text2, text3, text4, notes_spec FROM location_table WHERE location_reference=g
As you can see, in this case the String = 'g', but it seems to looking for a column called 'g' instead of looking at the data!
Very confused why this works with long but not String. Help appreciated as always.