我正在使用 SQLite 的 GreenDAO
ORM,我面临的问题是我有一个名为 TABLE 的表,我使用以下命令创建表:
db.execSQL("CREATE TABLE 'TABLE' (" + //
"'_id' INTEGER PRIMARY KEY ," + // 0: id
"'TYPE' INTEGER NOT NULL ," + // 1: Type
"'NAME' TEXT NOT NULL ," + // 2: Name
"'NUMBER' INTEGER NOT NULL ," + // 3: Number
"'CHAIRS' INTEGER NOT NULL ," + // 4: Chairs
"'NOTE' TEXT NOT NULL ," + // 5: Note
"'PRIORITY' INTEGER NOT NULL ," + // 6: Priority
"'STATUS' INTEGER NOT NULL ," + // 7: Status
"'ID_RELATED_RECORD' INTEGER NOT NULL ," + // 8: idRelatedRecord
"'REGISTERED_ON' INTEGER NOT NULL ," + // 9: RegisteredOn
"'REGISTERED_BY' TEXT NOT NULL ," + // 10: RegisteredBy
"'ID_TICKET_CATEGORY' INTEGER NOT NULL ," + // 11: idTicketCategory
"'ID_SEAT_MAP' INTEGER NOT NULL );"); // 12: idSeatMap
这可以通过创建表来按应有的方式工作,但是当我尝试通过以下方式选择所有数据时:
daoSession.getTableDao().queryBuilder().list();
这将引发此异常:
android.database.sqlite.SQLiteException: near "TABLE": syntax error
(code 1): , while compiling:
SELECT T.'_id', T.'TYPE',T.'NAME', T.'NUMBER',T.'CHAIRS', T.'NOTE', T.'PRIORITY', T.'STATUS', T.'ID_RELATED_RECORD', T.'REGISTERED_ON',T.'REGISTERED_BY', T.'ID_TICKET_CATEGORY', T.'ID_SEAT_MAP'
FROM TABLE T
我认为问题是该表被命名为"TABLE",但我不太确定?
不,你不能将表命名为TABLE,它是一个关键字。
sqlite 中的关键字列表: https://www.sqlite.org/lang_keywords.html
尝试使用这个逗号:",而不是这个:"