jeudi 23 avril 2015

Enter SQLite data if not exists

I'm trying to create a database with some records in it (if these don't exists yet). I now have the following code:

db = openOrCreateDatabase("DBNAME", Context.MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS tablename(id VARCHAR, name VARCHAR, active VARCHAR);");
db.execSQL("insert into tablename(id, name, active) VALUES ('1','name1','0');");
db.execSQL("insert into tablename(id, name, active) VALUES ('2','name2','1');");

What am I missing for inserting the data (if this doesn't exists yet)?

Aucun commentaire:

Enregistrer un commentaire