所以我试图从构造函数中将数据插入到sqlite数据库中:
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;
};
我想调用这个函数将这个“数据”放到这个“数据库”中:
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();
};
当我运行此代码时,它停在:
ins.run(data[dataArray[i]]);
期待8个值,但得到1。
更新 上面的代码插入多行,我想插入多个值而不知道长度IE:值(?1,?2,...?n)。
var InsertData = function(database, data){
database.run("INSERT into "+data.type+" values(?)",data);
};
那么我如何(如果可能的话)INSERT具有未知数量的值?