在设置我的应用程序时,我收到此错误,创建本地数据库并简单地插入第一个也是唯一的用户(谁已登录本地).请在代码中看到我收到错误消息的地方的注释.
angular.module("greenApp") .service("dbService",['$q',function($q){ var db; var promise = function(){ var deferred = $q.defer(); db = window.openDatabase('greenDB','1.0','Green Database',2*1024*1024); db.transaction(function(tx){ tx.executesql("CREATE TABLE IF NOT EXISTS user (user TEXT PRIMARY KEY) ") },function(err){ alert('Something went wrong... Error: DATABASE INIT ' + err); },function(scc){ deferred.resolve(); }) return deferred.promise; } promise(); var query = function(sql,args) { var deferred = $q.defer(); db.transaction(function(tx) { tx.executesql(sql,args,function(tx,results) { deferred.resolve(results); }); },function(err) { deferred.reject(err); }); return deferred.promise; }; var insert_into = function(args) { var queryPromise = query("INSERT INTO user (user) VALUES (?)",args); console.log("in insert_into",queryPromise) // Error message comes here return queryPromise; }; return { promise: promise,insert_into: insert_into,}; }]);
其中args只是[“user-name-string”],我收到一条错误消息:
“could not execute statement due to a constaint failure (19 UNIQUE
constraint Failed: user.user)
任何可能发生的想法?完全相同的代码正在运行,并在最近刚刚移植到Ionic的纯科尔多瓦项目中工作.