3 Replies Latest reply on Aug 20, 2012 9:57 PM by FreddyK

    How to copy sqlite database from applicationDirectory to documentsDirectory

    FreddyK

      I am having problems using the ‘File’ function in Adobe Flex to copy a sqlite database from the read only applicationDirectory to the users documentsDirectory.  When I use the code below the only thing that appears in the user documentsDirectory is a 1k to 4k file.  The actual file size of the database is around 350k.


       

      Am I not giving the file enough time to copy over?


       

      I am developing on a Mac but I think I remember duplicating the error on a PC as well.  This bug has been keeping me from launching my app for far too long.  Any ideas would be appreciated.


       

      Here is the code I am using:


      public function copyDB():void

      {

                var dbFile:File = File.applicationDirectory.resolvePath("db/myDataStorage.db");

                var dbWorkedFile:File = File.documentsDirectory.resolvePath("myDataStorage.db");

                if(!dbWorkedFile.exists){

                          trace("db Does Not Exist");

                          dbFile.copyTo(dbWorkedFile);

                } else {

                          trace("db Exists");

                          //The database has already been installed.  Launch app.

                }

                dbConn = new SQLConnection();

                dbConn.openAsync(dbWorkedFile);

      }


       

      I got the above code from this Adobe Cookbook recipe:

      http://cookbooks.adobe.com/post_Include_existing_SQLite_database_in_an_AIR_applica-10483.h tml

       

      Thanks