Android Studio 3.0 canary 1 : SQL syntax error

ⅰ亾dé卋堺 提交于 2020-01-07 04:40:47

问题


I have a problem after upgraded to Android Studio 3.0 canary 1 from Android Studio 2.3

db.execSQL("CREATE TABLE IF NOT EXISTS " + Contract.COUNTRY_PATH + " (" +
                Contract.Country._ID + " INTEGER AUTO INCREMENT , " +
                Contract.Country.COLUMN_CITY_ID + " INTEGER PRIMARY KEY," +
                Contract.Country.COLUMN_COUNTRY_NAME + " TEXT," +
                Contract.Country.COLUMN_SUNRISE + " INTEGER," +
                Contract.Country.COLUMN_SUNSET + " INTEGER) ");

It shows an error.

'(',')',<column constraint> or comma expected ,got 'AUTO'

It was fine with Android Studio 2.3. Any suggestions. Thanks.


回答1:


The SQL syntax checker in Android Studio 3 is stricter than sqlite itself.

INTEGER AUTO INCREMENT in sqlite itself basically just results in a column with integer affinity. The mistyped AUTO INCREMENT is just noise. That's why it gets flagged in Studio but does not cause a syntax error in sqlite.

If you want an autoincrementing column, make it INTEGER PRIMARY KEY. If you really need the rowid reuse avoidance, then the column should be INTEGER PRIMARY KEY AUTOINCREMENT. Note that you can only have one primary key column in a table. See also: https://sqlite.org/autoinc.html




回答2:


Do not put any spaces in you column name.

I'm using Android Studio 3.0 beta7. Same problem still exists.




回答3:


CREATE TABLE yourtablename (id INTEGER primary key autoincrement NOT NULL, name TEXT, description TEXT, expValue INTEGER, category INTEGER NOT NULL REFERENCES categories (id), date TEXT)


来源:https://stackoverflow.com/questions/44205651/android-studio-3-0-canary-1-sql-syntax-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!