-5

I'm new in android. I'm using SQLite database to store data. I have 2 column in this database which are containing unique data for each user.

The problem is when user will get an update, then the update will override the personal data. I want to update the database except 2 columns.

Here is my Initialize Database:

INSERT INTO WORDS (_id, unlocked,solved,score,word,letters,image,suggestion) VALUES (1,1,0,0,'example','example','pics/example.png','example');

As you can see, the 'solved' and 'score' has 0 values. I don't want to update these values. So I don't want to drop the entire database before the update, I would like to keep those 2 values, and make sure the update is not override those data.

Psypher
  • 10,717
  • 12
  • 59
  • 83
Farkas Antal
  • 310
  • 3
  • 9

3 Answers3

1

Use like this

UPDATE table_name SET  column_name1='value', column_name2 = 'value1' WHERE condition_column='value'
Amsheer
  • 7,046
  • 8
  • 47
  • 81
0

You can check it with weather DB table contains that user id or not, if not then do insert query as you are doing If record found, just do updateQuery:

UPDATE WORDS set unlocked = 1, word = 'example',letters = 'example',image ='pics/example.png',suggestion='example' WHERE _id=1;
Kinnar Vasa
  • 397
  • 1
  • 9
0

I have to say, you need to research, because this tag it's very trivial. So I recommend you to read more about. this could be:

    DatosSQLiteHelper usdbh = new DatosSQLiteHelper(this, "myDatabase", null, 1);
    SQLiteDatabase db = usdbh.getWritableDatabase();
if(db != null)
    {
        //add all atributes for update
        ContentValues registre = new ContentValues();
        registro.put("myvar1", "value1");
        registro.put("myvar2", "value2");
        registro.put("myvar3", "value3");

        int numcol = db.update("mytable", register, "_id_="+1, null);
        if (numcol == 1)
        {
            Toast.makeText(this, "success", Toast.LENGTH_SHORT).show();
        }

    }
Rene Limon
  • 614
  • 4
  • 16
  • 34