I'm working on a small Phonegap Project, and have problems with finding the right syntax to insert into a WebSQL database. I'm reading a jSON response from an API and try to cache it to a WebSQL / SQLite database but always get an error message. The database is created, the table also... problem is the insert. For inserting the different Rows into the database I iterate over my JSON. All variables are set and shown when I display them with console.log. What am I doing wrong?
songdata = JSON.parse(songdata); // JSON Gespielte Songs für ALLE Clubs abfragen, in SQLite speichern, und bei "success" weiter an den clubboxstyler weiterleiten
db = window.openDatabase("database.db", "1.0", "Demo", -1);
db.transaction(function(tx){
tx.executeSql('CREATE TABLE IF NOT EXISTS activity_stream (id integer primary key autoincrement, band text, clubID integer, time text, title text)');
for (var kay in songdata)
{
var Xband = songdata[kay].band;
var XclubID = songdata[kay].clubID;
var Xtime = songdata[kay].time;
var Xtitle = songdata[kay].title;
console.log(Xtitle);
tx.executeSql('INSERT INTO activity_stream (id, band, clubID, time, title) VALUES (1, ?, ?, ?, ?), [1, Xband, XclubID, Xtime, Xtitle]');
}
}, function(e) {
console.log("ERROR: " + e.message);
});
Thank you for you help! Much appreciated.
Aucun commentaire:
Enregistrer un commentaire