SQLite Database Android, check if a record exists and save -
SQLite Database Android, check if a record exists and save -
i have database extends sqliteonhelper app of have create sure if, example, alter only title, should update record, otherwise normal insert.
this table:
public void oncreate(sqlitedatabase db) { string sql = "create table vasca(" + "_id integer primary key,"+ "titolonota text not null,"+ "testonota text not null,"+ "datanota date,"+ "colorenota integer not null,"+ "unique(id, titolonota)"+ // reviewed ")"; db.execsql(sql); } and boolean method insert:
public boolean insertnote(nota nota){ // boolean inizializzat false utilizzata come homecoming boolean resultinsert = false; // repository dei dati in modalità scrittura sqlitedatabase dblite = this.getwritabledatabase(); // utilizza united nations contentvalues come mappa di valori, dove le columns rappresentano le chiavi contentvalues values = new contentvalues(); values.put(sql_insert_or_replace, true); values.put("titolonota", nota.gettitolo()); values.put("testonota", nota.gettesto()); values.put("datanota", nota.getdata()); // ritorna una string sdf.format(nota.getdata()) values.put("colorenota", nota.getcolore()); // chiama il metodo insert su dblite, vasca è il nome della tabella // poichè ritorna united nations long, se negativo significa che l'inserimento non è riuscito long idinserimento = dblite.insert("vasca", null, values); // sfrutto la variabile long per fare united nations controllo se andato tutto ok if( idinserimento <= -1 ){ log.e(tag, "inserimento della nota non avvento"); resultinsert = false; }else{ resultinsert = true; // inserisce la nota passata al metodo nell'arraylist listnote chiamando il metodo add together } dblite.close(); homecoming resultinsert; } i think need create query. help or advice appreciated :)
you should either create separate method update record or create separate update query based on flag can set on status whether filled form has updated or blank form has opened. can check whether opened form blank or filled checking each field 1 1 if opening same form filled info blank form. if blank form has opened, can set flag="insert" , fire insert query/method or if filled form has updated , user has changed in form can checked comparing previous values, can set flag="update" , fire relevant update query in same method or can phone call separate update method.
android sqlite row
Comments
Post a Comment