I am attempting to use a SQLite database to store emails locally in android. When I first call context.getWritableDatabase(), the database does not yet exist and is created. I am getting a syntax error on the create statement... My code looks like this...
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);";
I am new to SQLite syntax and I have been searching for what could cause this with no avail. Any idea whats causing this? A database is really the best way to store such data locally.
The exact error reads as follows..
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);