在我的phonegap应用程序中,我收到了此错误。
[INFO:CONSOLE(0)] "forcibly closing database"
我在我的项目中尝试访问插件(后台服务插件)中的数据库导致问题。
我使用此Background service plugin在nexus设备中运行良好,但在三星设备中运行良好
如何解决这个问题。 示例代码:
function selectUser() {
var query = " userid,islogged FROM user where islogged=1";
transactionSelect(query,"login");
}
function transactionSelect(query,str){
db = window.openDatabase(DATABASE_NAME, DATABASE_VERSION, DATABASE_NAME, 10000000);
newStr = str;
db.transaction(
function(tx){
tx.executeSql("SELECT "+query,[],returnExistingUser,noDBError);
});
}
// query returns success
function returnExistingUser(results){
//alert(JSON.stringify(results));
if (results.rows.length == 0) {
window.location.hash = "#loginpage";
} else {
userName = results.rows.item(0).userid;
// background service called here
getServiceStatus();
storeObject.userId = "userId";
if(device.model == "SM-T331" || device.model == "SM-T210" || device.model == "SM-T111" || device.model == "SM-T110"){
setTimeout(function(){
window.location.hash = "#viewpage";
},4000);
}else{
window.location.hash = "#viewpage";
}
}
$.mobile.autoInitialize();
}
in service(插件)
public void getLoggedUser() {
String sqlQuery = "SELECT userid FROM user WHERE islogged=1";
Cursor cursor = db.rawQuery(sqlQuery, null);
if (cursor != null && cursor.getCount() > 0){
cursor.moveToFirst();
do {
username = cursor.getString(0);
}while(cursor.moveToNext());
Log.e("uname", username);
if(username != null){
//here another query will e exec
getOrders(username);
}
}else{
//Log.e("no data", "no data");
db.close();
}
}