0

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?

N J
  • 26,829
  • 13
  • 75
  • 94
Arlind
  • 8,201
  • 3
  • 30
  • 44
  • 1
    Change the name of the table to something that is not a SQL key word and reserved word. Although you can make it work, it is not worth it. Give a table a more descriptive name. – Gordon Linoff Jun 18 '15 at 17:04
  • 1
    This answer might be helpful: http://stackoverflow.com/a/23446378/3766946 Take a look. – aashima Jun 18 '15 at 17:13
  • Now I changed the table name to GUEST_TABLE and nothing works isn't programming fun! – Arlind Jun 18 '15 at 17:26

2 Answers2

1

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

1

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

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

isma3l
  • 3,768
  • 1
  • 21
  • 28