targetSdkVersion = 26 的 AIR SQLite 错误
AIR SQLite error with targetSdkVersion = 26
我有一个运行良好的移动应用程序 (android/ios),但是 Google 要求开发人员现在使用 targetSdkVersion 26(到目前为止我的版本是 19)。
现在我使用 26,出现错误 #3125:
SQLError: 'Error #3125: Unable to open the database file.', details:'Connection closed.', operation:'open', detailID:'1001'
这是我打开数据库的代码:
static private function openDatabase(datebaseName:String) {
sqlCon = new SQLConnection();
dbDir = File.documentsDirectory.resolvePath("ZANORG");
dbDirFile = File.documentsDirectory.resolvePath("ZANORG/" + datebaseName + ".db");
if (dbDirFile.exists) {
trace("File exists");
sqlCon.addEventListener(SQLEvent.OPEN, onDatabaseOpen);
sqlCon.open(dbDirFile); // Error #3125 is here
} else {
trace("File does not exist");
if (!dbDir.exists){
trace("Folder doesn't exist > Create");
try{
dbDir.createDirectory();
}catch (error:Error){
trace("ERROR");
return;
}
}
sqlCon.addEventListener(SQLEvent.OPEN, onDatabaseCreationOpen);
sqlCon.open(dbDirFile);
var strReq:String = "CREATE TABLE IF NOT EXISTS gamedata (Score INT)";
sqlquery(strReq);
strReq = "INSERT INTO gamedata (Score) values(0)";
sqlquery(strReq);
}
}
找了几天终于找到解决办法了,跟Organis说的一样是权限问题..
我 post 我的解决方案是针对任何遇到相同问题的人,而不是调用我的 openDatabase 函数,我调用这个 checkDatabase 函数:
private static function checkDatabase(databaseName:String){
dbDirFile = File.documentsDirectory.resolvePath("ZANORG/" + databaseName + ".db");
dbDir = File.documentsDirectory.resolvePath("ZANORG");
if (File.permissionStatus != PermissionStatus.GRANTED){
dbDir.addEventListener(PermissionEvent.PERMISSION_STATUS, function(e:PermissionEvent):void {
if (e.status == PermissionStatus.GRANTED){
openDatabase(databaseName);
}else{
// permission denied
}
});
try {
dbDir.requestPermission();
}catch(e:Error){
// another request is in progress
}
}else{
openDatabase(databaseName);
}
}
我有一个运行良好的移动应用程序 (android/ios),但是 Google 要求开发人员现在使用 targetSdkVersion 26(到目前为止我的版本是 19)。 现在我使用 26,出现错误 #3125:
SQLError: 'Error #3125: Unable to open the database file.', details:'Connection closed.', operation:'open', detailID:'1001'
这是我打开数据库的代码:
static private function openDatabase(datebaseName:String) {
sqlCon = new SQLConnection();
dbDir = File.documentsDirectory.resolvePath("ZANORG");
dbDirFile = File.documentsDirectory.resolvePath("ZANORG/" + datebaseName + ".db");
if (dbDirFile.exists) {
trace("File exists");
sqlCon.addEventListener(SQLEvent.OPEN, onDatabaseOpen);
sqlCon.open(dbDirFile); // Error #3125 is here
} else {
trace("File does not exist");
if (!dbDir.exists){
trace("Folder doesn't exist > Create");
try{
dbDir.createDirectory();
}catch (error:Error){
trace("ERROR");
return;
}
}
sqlCon.addEventListener(SQLEvent.OPEN, onDatabaseCreationOpen);
sqlCon.open(dbDirFile);
var strReq:String = "CREATE TABLE IF NOT EXISTS gamedata (Score INT)";
sqlquery(strReq);
strReq = "INSERT INTO gamedata (Score) values(0)";
sqlquery(strReq);
}
}
找了几天终于找到解决办法了,跟Organis说的一样是权限问题..
我 post 我的解决方案是针对任何遇到相同问题的人,而不是调用我的 openDatabase 函数,我调用这个 checkDatabase 函数:
private static function checkDatabase(databaseName:String){
dbDirFile = File.documentsDirectory.resolvePath("ZANORG/" + databaseName + ".db");
dbDir = File.documentsDirectory.resolvePath("ZANORG");
if (File.permissionStatus != PermissionStatus.GRANTED){
dbDir.addEventListener(PermissionEvent.PERMISSION_STATUS, function(e:PermissionEvent):void {
if (e.status == PermissionStatus.GRANTED){
openDatabase(databaseName);
}else{
// permission denied
}
});
try {
dbDir.requestPermission();
}catch(e:Error){
// another request is in progress
}
}else{
openDatabase(databaseName);
}
}