Android Studio 3.0 Canary 1:SQL语法错误 [英] Android Studio 3.0 canary 1 : SQL syntax error

查看:532
本文介绍了Android Studio 3.0 Canary 1:SQL语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从Android Studio 2.3升级到Android Studio 3.0 Canary 1后,我遇到了问题

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) ");

显示错误.

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

使用Android Studio 2.3很好. 有什么建议. 谢谢.

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

推荐答案

Android Studio 3中的SQL语法检查器比sqlite本身更严格.

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

INTEGER AUTO INCREMENT基本上只导致具有整数亲和力的列.错误键入的AUTO INCREMENT只是噪音.这就是为什么它在Studio中被标记但在sqlite中不会引起语法错误的原因.

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.

如果要自动递增列,请将其设置为INTEGER PRIMARY KEY.如果您确实需要避免rowid重用,则该列应为INTEGER PRIMARY KEY AUTOINCREMENT.请注意,表中只能有一个主键列.另请参见: https://sqlite.org/autoinc.html

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

这篇关于Android Studio 3.0 Canary 1:SQL语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆