2

After hours (basically the entire day) of wriggling around, wrapping my throughts and whatnot, I am baffled as to why my UPDATE statement in SQLite does not want to work. It concerns the following queries:

sql.Update("UPDATE SAVEGAME SET _id = \"save\" WHERE _id = null");
sql.Update("UPDATE SAVEGAME SET WORLD_ONE = \""+finishedLevels+"\" WHERE _id = 'save'");

I've also tried

sql.Update("UPDATE SAVEGAME SET _id = 'save' WHERE _id = null");
sql.Update("UPDATE SAVEGAME SET WORLD_ONE = '"+finishedLevels+"' WHERE _id = 'save'");

but to no avail.

The function I'm calling is this:

public void Update(String query){
    SQLiteDatabase db = this.getWritableDatabase();
    db.execSQL(query);

    db.close();
}

Debugging clearly shows that the functions is being called and stepped through but refuses to work. Any other SQL function I call (e.g. to create new tables etc.) all have their db.close() call present.

I've also tried looking at a different project where the UDPATE statement does work, but I can't find any differences (instance of my SQLLib class, function calls are the same, etc.) It would seem so simple to call an UPDATE statement, but it has a fault somewhere.

Where is this fault? Because I'm at a total loss now.

-Zubaja

Zubaja
  • 251
  • 3
  • 18

1 Answers1

2

You are using = null when you need to use is null:

Change:

sql.Update("UPDATE SAVEGAME SET _id = \"save\" WHERE _id = null");

To this:

sql.Update("UPDATE SAVEGAME SET _id = \"save\" WHERE _id is null");
                                                        ^^^^

Also, you may want to check how you are creating your SQL strings - inserting variables like that leaves your code prone to SQL Injection attacks.

Todd
  • 30,472
  • 11
  • 81
  • 89
  • I'm on my way home from work now, so I'll update my findings in about an hour or so. Thank you for the swidt reply. – Zubaja Jan 22 '15 at 16:12
  • This was exactly the issue. It's one of those small things you overlook too quickly if you think the issue isn't where you think it is. Many thanks! – Zubaja Jan 22 '15 at 19:28