3 Replies Latest reply on Sep 15, 2011 5:02 PM by kokorito

    Mobile project, SQLite, database overwritten when app starts

    rtalton Level 4

      This is a mobile app targeted for Android. I've created a small database in which I want to store user preferences. Unfortunately, the database gets deleted each time the app is launched in debug mode. This happens without any code being run at all.

       

      The other strange thing is the database then gets re-created when my creation complete handler is entered, before a single line of code is run. You can see in the code below that this is where I start using the database, but again, the database is being wiped out and re-created before any of this code is reached.

      Result: I lose anything stored in the database.

       

      Any ideas why this is happening?

       

       

      <?xml version = "1.0" encoding = "utf-8"?>
      <s:View xmlns:fx = "http://ns.adobe.com/mxml/2009"
        xmlns:s = "library://ns.adobe.com/flex/spark"
        title = "HomeView"
        creationComplete = "view1_creationCompleteHandler(event)">

       

      //Removing creationComplete property, above, and then just running the app in debug deletes the stored database, without running the function below.


      <fx:Script>
        <![CDATA[
         import mx.events.FlexEvent;
         public var sqlc:SQLConnection = new SQLConnection();
         public var db:File;

       

          //If this function is entered, the "Local Store" folder (under the applicationStorageDirectory),
          //and the database, are deleted.

         protected function view1_creationCompleteHandler(event:FlexEvent):void {
         
          //stopping at the trace statement below will still re-create an existing database,
          //even if you terminate the debug session while stopped at this point.
          trace();
         
          db = File.applicationStorageDirectory.resolvePath("MyDatabase.db");
          //add the new listeners for attempting to open as read/write:
          sqlc.addEventListener(SQLEvent.OPEN, open_db_read_write_RESULT_event_handler);
          sqlc.addEventListener(SQLErrorEvent.ERROR, open_db_read_write_ERROR_event_handler);
          sqlc.openAsync(db)
         }

         private function open_db_read_write_RESULT_event_handler(event:SQLEvent):void {
          trace();
          //remove the listeners:
          sqlc.removeEventListener(SQLEvent.OPEN, open_db_read_write_RESULT_event_handler);
          sqlc.removeEventListener(SQLErrorEvent.ERROR, open_db_read_write_ERROR_event_handler);

         }

         private function open_db_read_write_ERROR_event_handler(event:SQLErrorEvent):void {
          trace();
          //remove the listeners:
          sqlc.removeEventListener(SQLEvent.OPEN, open_db_read_write_RESULT_event_handler);
          sqlc.removeEventListener(SQLErrorEvent.ERROR, open_db_read_write_ERROR_event_handler);
         }
        ]]>
      </fx:Script>
      <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
      </fx:Declarations>
      </s:View>

       

       

      Flash Builder 4.5.1

      Win 7

      My applicationStorageDirectory path, where the database is being created/stored:

      C:\Documents and Settings\MyName\AppData\Roaming\testSQL.debug\Local Store