When attempting to insert a new entry into a SQLite database in Android, the insert fails due to a syntax error. It seems that the query formed does not contain the values added to the ContentValues instance, but I'm not sure why. Can anyone point me to the error?
Here is the error message:
E/SQLiteLog: (1) near "TEXT": syntax error
E/SQLiteDatabase: Error inserting TIME_DATE TEXT=barbaz TRANSCRIPT TEXT=foobar
android.database.sqlite.SQLiteException: near "TEXT": syntax error (code 1): , while compiling: INSERT INTO approvals_t(TIME_DATE TEXT,TRANSCRIPT TEXT) VALUES (?,?)
And here is the code I'm using to test it:
public boolean insertData(String transStr, String timeStr) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cValues = new ContentValues();
cValues.put(TRANS_COL,"foobar");
cValues.put(TIME_COL,"barbaz");
// res is -1, the values couldn't be inserted
long res = db.insert(APVLS_TABLE_NAME,null,cValues);
if(res != -1)
return true;
else
return false;
}
(Edit) The rest of the code
public class DBHelper extends SQLiteOpenHelper implements BaseColumns {
public static final String DB_NAME = "Transcripts.db";
public static final String APVLS_TABLE_NAME = "approvals_t";
public static final String ID_COL = BaseColumns._ID;
public static final String TRANS_COL = "TRANSCRIPT TEXT";
public static final String TIME_COL = "TIMEDATE TEXT";
public DBHelper(Context context) {
super(context, DB_NAME, null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
// Create a sql command that builds a table
String SQL_CREATE_APVLS_TABLE = "CREATE TABLE " + APVLS_TABLE_NAME + " ("
+ ID_COL + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ TRANS_COL + ", "
+ TIME_COL + ");";
// Execute sql statement
db.execSQL(SQL_CREATE_APVLS_TABLE);
}