【发布时间】:2017-02-03 00:11:19
【问题描述】:
我需要将一些 JSON 格式的数据从请求中插入到我的应用程序的 SQLite 数据库中。数据库正在工作并且表存在,但我不知道如何让这个函数插入到表中。 以下是我到目前为止的代码。为什么它不做 INSERT?
synchronizeData() {
let db = new SQLite();
let loader = this.loadingCtrl.create({
content: "Sincronizando..."
});
loader.present();
this.account.allAccounts()
.subscribe(data =>
{
this.list = [];
//if (data.rows.length > 0) {
console.log(data.length);
for (var i = 0; i < data.length; i++) {
this.AccountId = data.rows.item(i).Id;
this.AccountIdentification = data.rows.item(i).Identification;
this.AccountActive = data.rows.item(i).Active;
this.AccountEditionUserId = data.rows.item(i).EditionUserId;
this.AccountEditionDateTime = data.rows.item(i).EditionDateTime;
this.AccountAccountTypeId = data.AccountType.rows.item(i).Id;
this.AccountComplement = data.rows.item(i).Complement;
this.AccountPriceListId = data.rows.item(i).PriceListId;
this.AccountColor = data.rows.item(i).Color;
this.AccountReferenceKey = data.rows.item(i).ReferenceKey;
if (data.rows.item(i).Active == 'true') { this.AccountActive = 1 } else { this.AccountActive = 0 }
//this.results.push({ name: data.rows.item(i).name });
this.db.executeSql("INSERT INTO Accounts" +
"(Id, SId, Identification, Active, EditionUserId, EditionDateTime, AccountTypeId, Complement, PriceListId, Color, ReferenceKey)" +
"VALUES(" + this.AccountId + ", 0 ," + this.AccountIdentification + " , " + this.AccountActive + " , " + this.AccountEditionUserId + "," +
this.AccountEditionDateTime + ", " + this.AccountAccountTypeId + "," + this.AccountComplement + "," + this.AccountPriceListId + "," +
this.AccountColor + "," + this.AccountReferenceKey +
")", []).then((data) => {
console.log("insert", data);
}, (error) => {
console.log("ERROR: " + JSON.stringify(error));
},
() => {
loader.dismiss();
})
}
//}
});
【问题讨论】:
标签: json sqlite angular ionic2