Reputation: 20538
I am developing an iOS app in Appcelerator (SDK 1.7.2). I am trying to save the content of a API call (JSON) into a local database on the device. I am using the code below but no posts are saved. The insert statement works fine outside the loop. I am working in a single context app if that has anything to do with it.
// Open the DB connection
var db = Titanium.Database.open('thedatabase');
// Create tables if they do not exist
db.execute('CREATE TABLE IF NOT EXISTS contacts (contact_id INTEGER, token TEXT, fullname VARCHAR, message TEXT, datetime VARCHAR, avatar TEXT, favorite INTEGER)');
// Get the data
Xhr.GET ({resource: 'contacts/all.json?'}, function (json) {
// Loop trough the JSON response
for (var i = 0; i < json.contacts.length; i++) {
// Insert contact to the database
db.execute('INSERT INTO contacts (contact_id, token, fullname, message, datetime, avatar, favorite) VALUES(?,?,?,?,?,?,?)', '0','1','2','3','4','5','6');
}
});
// Close the database
db.close();
Upvotes: 0
Views: 465
Reputation: 26
The community is already helping you locate the answer over on Q&A: http://developer.appcelerator.com/question/125036/cannot-insert-into-database
Upvotes: 1