【发布时间】:2014-07-01 17:13:04
【问题描述】:
我正在关注http://developer.android.com/training/basics/data-storage/databases.html 的指南
为满足我的需要进行了细微的更改,但我的应用程序在尝试创建表时立即崩溃。 Logcat 在索引附近显示一个 sqlite 异常,语法错误。即使我已经检查了三倍并且语法看起来正确。
异常显示:near "index": syntax error (code 1): , while compiling: CREATE TABLE my_locations ( index INTEGER PRIMARY KEY, loc_name TEXT, loc_id TEXT);
这是我的代码
private static final String TEXT_TYPE = " TEXT";
private static final String COMMA_SEP = ", ";
private static final String SQL_CREATE_ENTRIES =
"CREATE TABLE " + FeedEntry.TABLE_NAME + " ( " +
FeedEntry.COLUMN_NAME_INDEX + " INTEGER PRIMARY KEY, " +
FeedEntry.COLUMN_NAME_LOC_NAME + TEXT_TYPE + COMMA_SEP +
FeedEntry.COLUMN_NAME_LOC_ID + TEXT_TYPE +
");";
private static final String SQL_DELETE_ENTRIES =
"DROP TABLE IF EXISTS " + FeedEntry.TABLE_NAME;
// If you change the database schema, you must increment the database version.
public static final int DATABASE_VERSION = 1;
public static final String DATABASE_NAME = "PersonalLocations.db";
public PersonalLocationsDbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public void onCreate(SQLiteDatabase db) {
db.execSQL(SQL_CREATE_ENTRIES);
}
【问题讨论】: