jeudi 1 janvier 2015

SQLite insert overwriting data

I am developing application which receive the incoming notifications and save them in database. I have a problem that whenever a new message received it overwrite all the tuples in the database for example I received 13 messages my database will contain 13 tuples but all have the same value of the last received on. This is my code of inserting note that I tried two methods of inserting one is commented and the other is not and the two gave the same problem. Regards



public void addDBMessage(de.ecspride.reactor.poc.model.Message message) {
// datasource = new DBDataSource(null);

// Log.i("MessageStore", "Message added called the database");
// List<String> patterns = findPat();

// for (int i = 0; i < patterns.size(); i++) {
//
// String pattern = patterns.get(i);
// Log.i("MessageStore", pattern);
// if ((message.toString()).matches(pattern)) {

ContentValues values = new ContentValues();
values.put("APP", message.app);
values.put("TIME", message.time);
values.put("SENDER", message.sender);
values.put("MESSAGE", message.message);
// Inserting Row
open(); // opening database connection

database.insert("DATA", null, values);
close(); // Closing database connection
Log.i("MessageStore", "Message added sucessfully to the database");


// try {
// String ADD = "INSERT INTO DATA VALUES ('" + message.app.toString() + "','" + message.time.toString()
// + "','" + message.sender.toString() + "','" + message.message.toString() + "')";
// database.execSQL(ADD);
// Log.i("MessageStore", "Message added sucessfully to the database");
//
//// }
//// }
// } catch (Exception e) {
// Toast.makeText(null, "ERROR " + e.toString(), Toast.LENGTH_LONG).show();
//
// }
}


My database creation String is



public static final String TABLE_CREATE =
"CREATE TABLE " + TABLE_DATA + " (" +
"APP TEXT, TIME TEXT, SENDER TEXT, MESSAGE TEXT )";

Aucun commentaire:

Enregistrer un commentaire