Search code examples
javascripttitaniumtitanium-mobile

Titanium appcelerator sqlite


Can anyone tell me why im getting an invalid sql statement and how i can fix it. is there a particular way i have to use the SET?

lastrow is a variable that saves the last row id. listArray is an array that i push data to and then update the sql database.

i have tried.

SET SavedListSub = "ListArray"

and

SET SavedListSub = 'ListArray'

along with the below code given.

db.execute('UPDATE SavedList SET SavedListSub = listArray WHERE rowid=lastrow');

Solution

  • Use parameterized queries, as shown here

    Example:

    db.execute('UPDATE condition SET icon=? WHERE id=?',importIcon,dbConditionId);

    However, saving an array to a field in SQLITE probably isn't going to work. Depending on how you are going to structure your database, you could either iterate over the array and save the array items as individual records, or flatten out the array to a string prior to inserting it. You'd then have to convert it back to an array when reading the record from the db. More info on that here.