开发者

Android database tables syntax errors

I am trying to create a database with the name of a string stored in a local variable with the following syntax:

mDb.execSQL("CREATE TABLE " + FLASH_TABLE + " 开发者_StackOverflow中文版(" + KEY_CARD_ROWID
                + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_QUESTION
                + "TEXT NOT NULL," + KEY_ANSWER + "TEXT NOT NULL);");

which produces the following error in log cat:

05-14 04:40:05.892: ERROR/Database(372): Failure 1 (near "15": syntax error) on 0x272140 when preparing 'CREATE TABLE 15 (_id INTEGER PRIMARY KEY AUTOINCREMENT, questionTEXT NOT NULL,answerTEXT NOT NULL);'.

with FLASH_TABLE being the local variable with the value "15" KEY_QUESTION and KEY_ANSWER are also local variables

I have looked at every example online that I could find and I can not find the reason for the syntax error. I appreciate any advice you can offer.


You cannot create a table name (or a field name, for that matter) with a string that begins with a number unless you double-quote it. But even though it's technically possible, it's not considered a best practice. If you do, you will also have to double-quote the table name every time you use it in a query so you will quickly find that it's more trouble than it's worth.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜