I'd like to update a SQLite DB within an iPhone app via a JSON call and I'm wondering if i'm approaching it the right way and would be keen for your feedback/input.
I was thinking of using a JSON encoded string containing x-number of dictionaries in an array.
Each dictionary would have a few properties that correspond to the CRUD function i'd like to execute within the app, as well as the data I would like updated/deleted/added - i'm thinking it might look something like this...
[{ "crudFunction": "INSERT", "name": "John", "city": "city1", "phone": 11111},
{ "crudFunction": "UPDATE", "name": "Andrew", "city": "city2", "phone": 22222},
{ "crudFunction": "DELETE", "name": "Matt", "city": "city3", "phone": 33333},
{ "crudFunction": "UPDATE", "name": "Mike", "city": "city4", "phone": 44444} ]
For the sake of keeping things simple, in the above example i'll be updating the same table.
Not having a great knowledge of Objective C - I was wondering if I could construct my SQL statement using the variables I grabbed from the above array/dictionary? Something like:
NSString *insertQuery = @"INSERT INTO my_table (name, city, phone){[name],[city],[phone]}";
or in the case of an update...
NSString *insertQuery = @"UPDATE my_table SET city=[city], phone=[phone] WHERE name=Mike";
I'm thinking that in scenario's where I would have multiple updates to make, I could create a CRUD Object (of sorts) containing (transaction related) CRUD records/variables e.g. a DELETE Object containing all the records I would like to delete from my DB, or an UPDATE Object containing all the records/values I wanted to update.
Does this all make sense? Am I going about this the right way? Or should I just put down what i'm smoking and get back to my day job?
Thanks in advance Vortex