我正在尝试访问一个工作正常的数据库(直到我添加了更多字段并相应地更新了代码)。
我收到此错误:
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();
}
}
如果需要更多信息来解决此错误,请告诉我您的需求。 我真的很困惑于“,”。
答案 0 :(得分:1)
“cast”是一个保留字。尝试更改该列名称或引用它。 www.sqlite.org/lang_keywords.html
答案 1 :(得分:1)
请将强制转换键强化的值更改为其他值,因为强制转换是一个保留字。