Why do the IGNORE statement doesn't work? Everytime I run this the same value were insert in the database and I don't know why?
myDB = this.openOrCreateDatabase(MY_DB_NAME, MODE_PRIVATE, null);
myDB.execSQL("INSERT OR IGNORE INTO " + MY_DB_TABLE + "(db_datum, db_zahlen, db_scheine)"
+"VALUES ('"+datum+"',"+
"'"+zahlen+"',"+
"'"+9+"');");
db schema is:
db_datum (varchar(100))
db_zahlen (varchar(100))
db_scheine (integer)
I have the 2 String "datum" and "zahlen" and would like to insert them in the database. Now the problem is, if the same strings are already in the db and the code run again they sould be ignored and never insert again.
You can use insertWithOnConflict. Ex:
mDb.insertWithOnConflict(DATABASE_TABLE, null, initialValues, SQLiteDatabase.CONFLICT_IGNORE);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With