I'm trying to update my database with the following line of code:
db.execute('UPDATE table SET val=? WHERE gID = ? VALUES(?,?)','true',gID)
I'm not really sure though what I'm doing and something with the above code is wrong. Does anyone know?
Likely this is the syntax you're looking for:
db.execute('UPDATE table SET val=? WHERE gID=?','true',gID)
That's assuming that "val" column type is string. If instead you want boolean, then you should switch to using integers (0 or 1) according to: http://www.sqlite.org/datatype3.html
That's what I had originally, and no it's a string. However, it still doesn't work. It just closes the app. Any ideas?
Perhaps you can try an alternate syntax like
db.execute('UPDATE table SET val=true WHERE gID='+gID)
Alright. I think I figured the source of my problem. I'm getting a SQLite error: 'database table is locked'. After a quick google search, it appears that I cannot update and read my database. What's the methodology around that for titanium?
I've never encountered a 'table locked' error. My first guess would be to try to eliminate the obvious: mis-named table & database not open are two potential problems to check.
As for "what is the methodology" part of your question, the db.execute technique you're using is the Titanium way of updating a database. Make sure you've done the var db = Titanium.Database.open('your_db'); first.
So I should be able to update and insert in the same file? Good, because I saw that in the Kitchen Sink examples. And yes, I'm sure there are no typos. If I purposefully type something incorrect, then it gives me that error.
So does anyone know what the source of my problem is? Thanks, this is becoming a real road block in my project.
Looks like this is my issue:
How do I close the INSERT statement?
The implication in that other post is that a ResultSet was created and is still open on the table in question. In your code have you done a SELECT and stored the results in a ResultSet? If so, close that ResultSet before you attempt to do an UPDATE or INSERT.
Do I still need to close an UPDATE execution, even if the results are not put into a variable?
Thanks, updating no longer crashes my app. It just doesn't seem to actually be updating…