AIR SQLite错误,targetSdkVersion = 26

时间:2018-06-10 09:23:44

标签: android sqlite actionscript-3 air

我有一个很棒的移动应用程序(android / ios),但谷歌要求开发人员现在使用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);
        }
    }

1 个答案:

答案 0 :(得分:0)

经过几天的寻找,我终于找到了解决方案,这是一个像Organis所说的许可问题。

我将解决方案发布给有相同问题的任何人,而不是调用我的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);
        }       

    }