Android SQLite can a tables name be 'TABLE'

79 views Asked by At

I'm using the GreenDAO ORM for SQLite, The problem i'm facing is that I have a table named TABLE, I use the following command to create the 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

This works the way it should by creating the table but when i try to select all the data by:

daoSession.getTableDao().queryBuilder().list();

This throws this Exception:

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

I think that the problem is that the Table is named 'TABLE' but I'm not really sure?

2

There are 2 answers

0
isma3l On BEST ANSWER

No you can't name a table TABLE, it's a keyword.

List of keywords in sqlite: https://www.sqlite.org/lang_keywords.html

0
AudioBubble On

try use this comas: ``, not this: ' '