Reputation: 2527
I'm creating a table before adding information to it because I need its ID. Code:
ContentValues values = new ContentValues();
Long id = db.insert(PersonEntry.TABLE_NAME, PersonEntry.COLUMN_NAME_NULLABLE, values);
However, I get this error:
near "NULL": syntax error
Error inserting
near "NULL": syntax error (code 1): , while compiling: INSERT INTO person(NULL) VALUES (NULL)
The code works if I put some fake values in values, but that shouldn't be necessary given the nullColumnHack. What am I missing?
Schema:
public static abstract class PersonEntry implements BaseColumns {
public static final String COLUMN_NAME_NULLABLE = "NULL";
...
}
Creation of table:
private static final String SQL_CREATE_ENTRIES =
"CREATE TABLE " + PersonEntry.TABLE_NAME + " (" +
PersonEntry.COLUMN_NAME_NULLABLE + TEXT_TYPE + COMMA_SEP +
...
" )";
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(SQL_CREATE_ENTRIES);
}
Upvotes: 0
Views: 1712
Reputation: 4411
Use a name other than NULL
for your null column, it's a reserved word. Something like NULLHACK
might be better. Alternatively, name one of your other columns as the null column hack.
Upvotes: 2