I'm trying to insert into sqlite which has a default value for on of its column. I'm using SQLiteStatement for this goal. I create my table like below
public static void createTable(SQLiteDatabase db, boolean ifNotExists)
{
String constraint = ifNotExists? "IF NOT EXISTS ": "";
db.execSQL("CREATE TABLE " + constraint + "\"DBUSER\" (" +
"\"BLOCKED\" INTEGER DEFAULT 0 ," +
"\"USERNAME\" TEXT," +
"\"USER_ID\" TEXT PRIMARY KEY NOT NULL );");
}
And i insert into it like this
@Override
protected void bindValues(SQLiteStatement stmt, DBUser entity) {
stmt.clearBindings();
Boolean blocked = entity.getBlocked();
if (blocked != null) {
stmt.bindLong(1, blocked ? 1L: 0L);
}
String username = entity.getUsername();
if (username != null) {
stmt.bindString(2, username);
}
String userId = entity.getUserId();
if (userId != null) {
stmt.bindString(3, userId);
}
}
The question is this, how can i insert an item which has default value on 'blocked' value in this structure?
Thanks in advance
Aucun commentaire:
Enregistrer un commentaire