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