1 Reply Latest reply on Jan 5, 2011 10:42 PM by Mayank (Adobe)

    [Burrito] Connect to SQLite DB

    DishDev

      Hi All,

       

      Im having a hell of a time trying to create/connect to a local database (SQLite) on Android 2.2 HTC Evo.

      I began by creating the database on the fly at startup if one didnt exist. This works like a champ on a Windows machine, but wont create the database on the SDCard. Man, the lack of docs is killing me. Can someone give me some insight or a work around the this?

       

      Thanks,

      Stephan

       

      ----------------------------------------------------------------------------------------- ---------------------

      Example Part 1:

       

            import flash.data.SQLConnection;

       

          public var conn:SQLConnection = new SQLConnection();
          public var thisPath:String;

       

          private function checkDatabase():void
          {
              var db:File = File.desktopDirectory.resolvePath('TechConnect.db');
             
              thisPath = db.nativePath.toString();
              trace(db.nativePath.toString());
              if(!db.exists)
              {
                  conn.addEventListener(SQLEvent.OPEN,connOpenHandler);
                  conn.addEventListener(SQLErrorEvent.ERROR,connErrorHandler);
                  conn.openAsync(db);
              }
          }
         
          private function connOpenHandler(event:SQLEvent):void
          {
              trace("the database was created successfully");
              if(conn.connected)
              {
                  var stmt:SQLStatement = new SQLStatement();
                  stmt.sqlConnection = conn;
                  var sql:String = "CREATE TABLE [tablename] (my fields here.....)";
                  stmt.text = sql;
                  stmt.execute();
              }
             
          }
         
          private function connErrorHandler(event:SQLErrorEvent):void
          {
              trace("Error message:", event.error.message);
              trace("Details:", event.error.details);
          }

       

      ----------------------------------------------------------------------------------------- ---------------------