4

I'm using the following statement to insert values in my table in SQLITE:

public void insertStocuri(Integer rucsaci,Integer kituri, Integer sticle)
    {
        ContentValues newValues = new ContentValues();

                newValues.put("Rucsaci", rucsaci);
                newValues.put("Kit",kituri);
                newValues.put("Sticle",sticle);


        Cursor query =db.query("STOCURI", null, null, null, null, null, null);

        if(query.getCount()<1)


        {

        //db.replace("STOCURI", null, newValues);
        db.insert("STOCURI", null, newValues);
        ///Toast.makeText(context, "Reminder Is Successfully Saved", Toast.LENGTH_LONG).show();

        }

        else {
            db.update("STOCURI",newValues, null, null);

        }
        }

i've updated the question with the solution that works for me...

Rares Biris
  • 195
  • 1
  • 3
  • 18
  • 1
    check http://stackoverflow.com/questions/15707796/sqlitedatabase-insert-only-if-the-value-does-not-exist-not-via-raw-sql-command and http://stackoverflow.com/questions/9656803/android-sqlite-insert-record-if-not-exists – Jaiprakash Soni Jul 28 '15 at 08:54
  • Use `REPLACE INTO`: It will `INSERT` a new record, if not existing or `UPDATE` it, if already existing – Phantômaxx Jul 28 '15 at 09:08

0 Answers0