Question

Im creating an sqlite db in my air for android app inside the following function:

protected function createDatabase():void{

        _sqlConnection = new SQLConnection();
        _sqlConnection.addEventListener(SQLEvent.OPEN, openHandler); 
        _sqlConnection.addEventListener(SQLErrorEvent.ERROR, errorHandler); 

        var _sqlFolder:File = File.applicationStorageDirectory; 
        var _sqlFile:File = _sqlFolder.resolvePath("RouteLog.db");          

        _sqlConnection.open(_sqlFile); 
}

i can successfully create tables, insert and select, but each time i re-publish the app from flash cs5.5 the database is overwritten and all data is lost. Totally stumped, any ideas welcome!

Cheers

[edit]

so, i'm publishing a debug release directly from flash pro via usb. When the app is initialised it calls the method above, on receiving the OPEN event it creates a table using the following SQL statement

var SQL:String =            
            "CREATE TABLE IF NOT EXISTS myRoutes (" +
            "id INTEGER PRIMARY KEY AUTOINCREMENT, " +
            "name STRING, " + 
            "created DATE, " + 
            "duration NUMBER, " + 
            "waypoints OBJECT, " + 
            "avgSpeed NUMBER, " +
            "distance NUMBER, " +
            "rating NUMBER" + ")";

I can then run some operations, insert, select etc and everything is as expected. If i exit and re-luanch the app, the previous data sets are intact, but when i re-publish from flash any data stored from the previous release has disappeared.

According to the documentation SQLConnection.open() will open a connection to the file supplied in the parameters and if it doesn't exist, it will create one...

Was it helpful?

Solution 2

After further research on the adobe forums I think the answer is that you cannot prevent files stored in the applicationStorageDirectory from being overwritten when re-publishing from Flash Pro.

The app im building uses Geolocation as a core feature, so I need a real data set to work with. The solution in the end that worked for me, was to copy the database from applicationStorageDirectory to documentsDirectory (sd card) whilst i'm still developing the app (will remove this if it ever gets to market).

OTHER TIPS

According to the AS3 reference for flash.filesystem.File:

When you uninstall an AIR application, whether the uninstaller deletes the application storage directory and its files depends on the platform.

So you may be running into that issue if you are manually uninstalling the app and then pushing it to the device again. More detail on the steps will help as I've definitely had data persist between app publishes to an Android device (though I was using Flash Builder).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top