我試圖訪問一個工作正常的數據庫(直到我添加了更多的字段並相應地更新了代碼)。訪問sqlite數據庫時,應用程序不斷崩潰
我得到這個錯誤:
Caused by: android.database.sqlite.SQLiteException: near ",": syntax error: , while compiling: SELECT _id, title, description, locations, datesTimes, added, provider, url, cast, director, runningTime, certification, imageUrl, trailerUrl FROM films ORDER BY _id DESC
下面是查詢代碼:
public Cursor getAllTitles()
{
return myDataBase.query("films", new String[] {
KEY_ROWID,
KEY_TITLE,
KEY_DESCRIPTION,
KEY_LOCATIONS,
KEY_DATESTIMES,
KEY_ADDED,
KEY_PROVIDER,
KEY_URL,
KEY_CAST,
KEY_DIRECTOR,
KEY_RUNNINGTIME,
KEY_CERTIFICATION,
KEY_IMAGEURL,
KEY_TRAILERURL},
null,
null,
null,
null,
KEY_ROWID + " DESC"); //Sort the data using the Primary Key in descending order . . meaning last added is shown first.
}
這裏從數據庫中提取數據的代碼:
//---Get all records from database---
myDbHelper.openDataBase();
cursorPosition = myDbHelper.getAllTitles();
if (cursorPosition.moveToFirst())
{
do {
AddRecordToArray(cursorPosition);
} while (cursorPosition.moveToNext());
}
myDbHelper.close();
}
public void AddRecordToArray(Cursor cursorPosition)
{
//Add new record to array (which gets data from database using cursorPosition (for current row) and .getstring(for column number).
final FilmRecord film1 = new FilmRecord(cursorPosition.getString(1), cursorPosition.getString(4), cursorPosition.getString(5), cursorPosition.getString(3), cursorPosition.getString(2), cursorPosition.getString(6), cursorPosition.getString(7), cursorPosition.getString(8), cursorPosition.getString(9), cursorPosition.getString(10), cursorPosition.getString(11), cursorPosition.getString(12), cursorPosition.getString(13));
films.add(film1);
myDbHelper.close();
}
@Override
protected void onDestroy() {
super.onDestroy();
if (myDbHelper != null) {
myDbHelper.close();
}
}
如果有任何更多的信息需要解決這個錯誤只是讓我知道你需要什麼。 我真的很困惑「,」。
實際創建查詢的代碼在哪裏?如果你在字段名稱周圍放置了backtics(「'」)(如果沒有看到它,但可能有一個字段名是保留的oid),會發生什麼情況 – Nanne 2012-03-01 13:28:05
繼承人鏈接[Pastie](http://pastie.org/3496361)顯示用於創建查詢的代碼:) – Odhran 2012-03-01 13:31:38
另一個鏈接到[Pastie](http://pastie.org/3496385),其中包含用於從數據庫提取數據的代碼。 – Odhran 2012-03-01 13:34:06