我试图在ionic + angular js项目中进行sqlite的简单演示。我在数据库中插入数据。但是我的错误函数先调用然后成功为什么? 按照步骤 1
这是我的代码 http://codepen.io/anon/pen/ZGYKvE
app.factory('sqlservice',function($q){
var db;
var task='';
var deleteTask;
function createDB(){
try{
db=window.openDatabase("ATMSDB","1.0", "ATMSDB", 10*1024*1024);
db.transaction(function(tx){
tx.executeSql('CREATE TABLE "Cases" ("ID" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , "CaseName" VARCHAR NOT NULL )');
})
}catch (err) {
alert(err);
}
}
function insertDataOnDataBase(testCaseName){
return promiseQuerry("INSERT INTO Cases (CaseName) VALUES ('"+testCaseName+"')",defaultResultHandler,defaultErrorHandler)
}
function promiseQuerry(query,success,error){
var defferrd =$q.defer();
db.transaction(function(tx){
tx.executeSql(query,[],success(defferrd),error(defferrd));
})
return defferrd.promise;
}
function defaultResultHandler(defferrd){
return function(tx,result){
alert("success")
var len=result.rows.length;
var output_results = [];
for (var i=0; i<len; i++){
var t = {'ID':results.rows.item(i).ID,'CaseName':results.rows.item(i).CaseName};
output_results.push(t);
}
defferrd.resolve(output_results);
}
}
function defaultErrorHandler(defferrd){
alert("error")
return function(tx, results) {
var len = 0;
var output_results = '';
defferrd.resolve(output_results);
}
}
return{
setup: function() {
return createDB();
},
insertData:function(testCaseName){
return insertDataOnDataBase(testCaseName);
}
}
})
其次:
我能够在数据库中插入数据但是我在表格中得到两列ID?