mercredi 15 avril 2015

How to insert multiple variables with one insert into sqlite

So i'm trying to insert data into a sqlite database from the constructor:



var EventData = function(ID, Name, StartDate, StartTime, EndDate, EndTime, Location, Notes){
this.type = "event";
this.id = ID;
this.name = Name;
this.startDate = StartDate;
this.startTime = StartTime;
this.endDate = EndDate;
this.endTime = EndTime;
this.location = Location;
this.notes = Notes;
};
EventData.prototype.count = function(){
return Object.keys(this).length;
};


And I want to call this function that will put this "Data" into this "database":



var InsertData = function(database, data){
var dataArray = Object.keys(data);
var ins = database.prepare("INSERT into "+data.type+" values(?)");
for(var i = 0; i < dataArray.length; i++){
ins.run(data[dataArray[i]]);
}
ins.finalize();
};


when I run this code It stops at:



ins.run(data[dataArray[i]]);


expecting 8 values but getting 1.


So how would I (if possible) INSERT with an unknown number of values?


Aucun commentaire:

Enregistrer un commentaire