我正在尝试使用 SQLite 数据库将电子邮件本地存储在 android 中。当我第一次调用context.getWritableDatabase()
时,数据库还不存在并被创建。我在 create 语句中遇到语法错误...我的代码如下所示...
private static final String DATABASE_NAME = "views.db";
private static final int DATABASE_VERSION = 1;
public static final String TABLE_VIEWS = "views";
private static final String KEY_ID = "id";
private static final String KEY_INDEX = "index";
private static final String KEY_FROM = "from";
private static final String KEY_UNREAD = "unread";
private static final String KEY_SUBJECT = "subject";
private static final String KEY_BODY = "body";
// Database creation sql statement
private static final String CREATE_VIEWS_TABLE = "CREATE TABLE " + TABLE_VIEWS + " ("
+ KEY_ID + " INTEGER PRIMARY KEY,"
+ KEY_INDEX + " INTEGER NOT NULL,"
+ KEY_UNREAD + " TEXT NOT NULL,"
+ KEY_SUBJECT + " TEXT NOT NULL,"
+ KEY_FROM + " TEXT NOT NULL,"
+ KEY_BODY + " TEXT NOT NULL);";
我是 SQLite 语法的新手,我一直在寻找可能导致这种情况的原因,但无济于事。知道是什么原因造成的吗?数据库确实是在本地存储此类数据的最佳方式。
确切的错误如下..
07-01 17:54:42.827: E/AndroidRuntime(3036): Caused by: android.database.sqlite.SQLiteException: near "index": syntax error: CREATE TABLE views (id INTEGER PRIMARY KEY,index INTEGER NOT NULL,unread TEXT NOT NULL,subject TEXT NOT NULL,from TEXT NOT NULL,body TEXT NOT NULL);