enter code here
我想寫一個查詢來提取我的Android SQLite數據庫表中位置引用=「一個字符串」的所有行。我使用下面的代碼在我的數據庫輔助類:查找字符串時數據庫查詢問題
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;
}
而且我把它在我的活動如下:
// Get a Cursor for the list items
Cursor listComponentCursor = rmDbHelper.fetchComponentsForLocation(locationRef);
startManagingCursor(listComponentCursor);
// set the custom list adapter
setListAdapter(new MyListAdapter(this, listComponentCursor));
然後把它在我的ListAdapter用於填充我的列表視圖。現在在我的其他活動中,當我基於id(即長)獲取行時,此代碼正常工作。當我與字符串嘗試它,我得到以下錯誤:
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
正如你所看到的,在這種情況下,字符串=「G」,但它似乎在尋找一個叫「G」列而不是看數據!
非常困惑爲什麼這個工作與長而不是字符串。幫助一如既往的讚賞。
太棒了 - 感謝您的幫助。顯然,當你知道! :) – Scamparelli