所以我一直在與Android上的SQLite摔跤,並已解決了一些問題。問題是here和here。selectionArgs錯誤表示列不存在
我現在想爲給定狀態選擇DISTINCT區域。我的第一個RecyclerView屏幕使用以下代碼顯示狀態。
public Cursor getStateData() {
SQLiteDatabase db = getReadableDatabase();
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
String [] sqlSelect = {"0 _id", "state" };
String sqlTables = "Reefs";
qb.setTables(sqlTables);
qb.setDistinct(true);
Cursor c = qb.query(db, sqlSelect, null, null, null, null, null);
c.moveToFirst();
return c;
}
我們得到不同的區域,因爲我使用下面的代碼每個狀態:
public Cursor getRegionData(String whichState) {
SQLiteDatabase db = getReadableDatabase();
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
String [] sqlSelect = {"0 _id", "region" };
String theState = whichState;
String sqlTables = "Reefs";
qb.setTables(sqlTables);
qb.setDistinct(true);
Cursor c = qb.query(db, sqlSelect, theState , null , null, null, null);
// (table, columms to return, colums for the where clause, values for the where clause, null, null, null)
c.moveToFirst();
return c;
}
而且它不工作,給我這個錯誤消息:
Caused by: android.database.sqlite.SQLiteException: no such column: Tasmania (code 1): , while compiling: SELECT DISTINCT 0 _id, region FROM Reefs WHERE (Tasmania)
我選擇塔斯馬尼亞島從列表中如此塔斯馬尼亞作爲字符串參數傳入其中狀態爲。
所以,如果我是來描述purly SQL方面的問題,它是這樣的:
SELECT
region //column in my table called region
FROM
Reefs // table in my database
WHERE
state = [the state selected] //column in my table called **state** which I pass in with the varible **whichState**
我在做什麼錯?
你爲什麼選擇'0'(常量)? –
我正在使用SQLiteAssetHelper和SQLite的新手使用這些傢伙的解決方案:https://github.com/jgilfelt/android-sqlite-asset-helper – timv