0 Replies Latest reply on Jul 2, 2010 9:41 AM by msf5042

    SQL getResults always null?

    msf5042

      I am having an issue that I cannot figure. I cannot select data from my SQL database, getResults() always returns null.... here is some of my code, any help is appreciated:

       

      public function init():void {

      conn.addEventListener(SQLEvent.OPEN, openHandler);

      conn.addEventListener(SQLErrorEvent.ERROR, errorHandler);

      dbFile = File.applicationStorageDirectory.resolvePath("ArnoldMagic.db");

      conn.openAsync(dbFile);

      createTables();

      }

       

      private function createTables():void {

       

      var settingsSQL:String =

      "CREATE TABLE IF NOT EXISTS settings (" +

      "    id INTEGER PRIMARY KEY AUTOINCREMENT, " +

      "    flashDuration TEXT, " +

      "    pauseDuration TEXT, " +

      "    manualOperation TEXT, " +

      "    listRandomized TEXT, " +

      "    recordResults TEXT " +

      ")";

       

       

       

      var initSettingsSQL:String = "INSERT INTO settings (flashDuration, pauseDuration, manualOperation, listRandomized, recordResults) " +

      "VALUES('1 second','1 second','YES','YES','YES')";

       

       

       

       

      var createSettings:SQLStatement = new SQLStatement();

      createSettings.sqlConnection = conn;

      createSettings.text = settingsSQL;

      createSettings.addEventListener(SQLEvent.RESULT, createResult); // ***************THIS GETS EXECUTED

      createSettings.addEventListener(SQLErrorEvent.ERROR, errorHandler);

      createSettings.execute();

       

      var initSettings:SQLStatement = new SQLStatement();

      initSettings.sqlConnection = conn;

      initSettings.text = initSettingsSQL;

      initSettings.addEventListener(SQLEvent.RESULT, createResult); //********THIS GETS EXECUTED

      initSettings.addEventListener(SQLErrorEvent.ERROR, errorHandler);

      initSettings.execute();

      }

       

      private function updateSettings():void {

      selectStmt = new SQLStatement();

      selectStmt.sqlConnection = conn;

      selectStmt.text = "UPDATE settings SET flashDuration = '" + flashDurationCombo.selectedItem + "'," +

      "pauseDuration='" + pauseDurationCombo.selectedItem + "'," +

      "manualOperation='" + manualOperationCombo.selectedItem + "'," +

      "listRandomized='" + listRandomizedCombo.selectedItem + "'," +

      "recordResults='" + recordResultsCombo.selectedItem + "' where id='1';";

       

      //selectStmt.addEventListener(SQLEvent.RESULT, updateSettingsHandler);

      //selectStmt.addEventListener(SQLErrorEvent.ERROR, errorHandler);

      try {

      selectStmt.execute();

      } catch(err:Error) {

      trace("ERROR (updateSettings): " + err.message);

      return;

      }

      getSettings();

       

      }

       

      public function getSettings():void {

       

      SQLstmt = new SQLStatement();

      SQLstmt.sqlConnection = conn;

      SQLstmt.text = "SELECT id FROM settings WHERE id='1'";

      try {

      SQLstmt.execute();

      } catch(err:Error) {

      trace("ERROR (getSettings): " + err.message);

      return;

      }

       

      var result:SQLResult = SQLstmt.getResult();

      if(result == null) { //******************THIS ALWAYS HAPPENS

      trace ("WARNING (getSettings): result null");

      return;

      }

       

      if(result.data == null) {

      trace ("WARNING (getSettings): data null");

      return;

      }

      settings = new ArrayCollection(result.data);

      //pauseDurationCombo.selectedItem = result.data[0];

      testLabel.text = settings[0];

      }