SQL Lite Update

Please see this link for original question …

http://developer.coronalabs.com/forum/2012/09/12/sql-lite-assign-variable-column

basically looking for someone who can show example on how to UPDATE sql table record with variables… everything I see on internet and corona API shows UPDATE of a field in the database table record using literal strings or numerals. Anyone have a sample code that shows updating a field in a sql table record with a variable?

Thanks [import]uid: 148857 topic_id: 30973 reply_id: 330973[/import]

@cyberparkstudios, please read this tutorial first:
http://www.coronalabs.com/blog/2012/04/03/tutorial-database-access-in-corona/
Ask me if you don’t understand something and maybe I will explain it to you. [import]uid: 138389 topic_id: 30973 reply_id: 123870[/import]

@vovasoft
Thanks!!

I have read this tutorial. It all makes sense. Inserting a record using table values seems to work fine as it is explained the link you sent. I had previously read that and accomplished inserting the record successfully when creating the database table and record.

Except I do not want to insert another ‘record’. I want to UPDATE the one existing record I have in the database table. This record holds the game data fields used in my app. When the app is in process some of these variables (credits, various state flags) change, and then on exit of the app, I want to update & save that database record by assigning these variables to the appropriate fields in ‘that’ database table record.

Nothing in this tutorial from the link or any other tutorial I have seen on the web shows when using the UPDATE command in SQL lite, how to assign a ‘variable’ to any of those fields for a record in the database. I would think this is such a common action there would have to be many examples out there and yet I see none.

Every example I have seen including the one for the link you provided when it is explaining UPDATE of a table record, it only shows assigning literals (strings or numbers). How do I UPDATE a field in the database table record… with a variable, in my Corona code. If you are able to type a short example, that would be of great help!

Thanks [import]uid: 148857 topic_id: 30973 reply_id: 123877[/import]

@cyberparkstudios
from tutorial in previous post:

local q = [[UPDATE test SET name='Big Bird' WHERE id=3;]]  
db:exec( q )  

to use variables just change it to:

local nameBird = "Big Bird" local idBird = 3 local q = [[UPDATE test SET name=']] .. nameBird .. [[' WHERE id=]] .. idBird .. [[;]] db:exec( q ) [import]uid: 138389 topic_id: 30973 reply_id: 123886[/import]

@vovasoft

Outstanding! Thanks much. The single quotes and interior double brackets make all the difference from what I was doing. It looks ugly, but it works.

All is working finally!
[[RESOLVED]] [import]uid: 148857 topic_id: 30973 reply_id: 123982[/import]

@cyberparkstudios, please read this tutorial first:
http://www.coronalabs.com/blog/2012/04/03/tutorial-database-access-in-corona/
Ask me if you don’t understand something and maybe I will explain it to you. [import]uid: 138389 topic_id: 30973 reply_id: 123870[/import]

@vovasoft
Thanks!!

I have read this tutorial. It all makes sense. Inserting a record using table values seems to work fine as it is explained the link you sent. I had previously read that and accomplished inserting the record successfully when creating the database table and record.

Except I do not want to insert another ‘record’. I want to UPDATE the one existing record I have in the database table. This record holds the game data fields used in my app. When the app is in process some of these variables (credits, various state flags) change, and then on exit of the app, I want to update & save that database record by assigning these variables to the appropriate fields in ‘that’ database table record.

Nothing in this tutorial from the link or any other tutorial I have seen on the web shows when using the UPDATE command in SQL lite, how to assign a ‘variable’ to any of those fields for a record in the database. I would think this is such a common action there would have to be many examples out there and yet I see none.

Every example I have seen including the one for the link you provided when it is explaining UPDATE of a table record, it only shows assigning literals (strings or numbers). How do I UPDATE a field in the database table record… with a variable, in my Corona code. If you are able to type a short example, that would be of great help!

Thanks [import]uid: 148857 topic_id: 30973 reply_id: 123877[/import]

@cyberparkstudios
from tutorial in previous post:

local q = [[UPDATE test SET name='Big Bird' WHERE id=3;]]  
db:exec( q )  

to use variables just change it to:

local nameBird = "Big Bird" local idBird = 3 local q = [[UPDATE test SET name=']] .. nameBird .. [[' WHERE id=]] .. idBird .. [[;]] db:exec( q ) [import]uid: 138389 topic_id: 30973 reply_id: 123886[/import]

@vovasoft

Outstanding! Thanks much. The single quotes and interior double brackets make all the difference from what I was doing. It looks ugly, but it works.

All is working finally!
[[RESOLVED]] [import]uid: 148857 topic_id: 30973 reply_id: 123982[/import]