1 Reply Latest reply on Mar 4, 2008 2:10 PM by enorton@adobe

    Code help on local db connection

    Funkystrat Level 1
      I have a simple db and want to pull that onto the stage into a TextArea with html format so I can use some of the db fields as urls. For testing I have this code creating two text fields, one with text.html call and one with the appent.text.

      The first textarea displays my text in html format, but only the last row in the database, the second box ignores the html, but also only shows me the last item in the db. My trace returns all the rows in the db.

      Please help, I have looked everywhere...

      import flash.data.SQLConnection;
      import flash.data.SQLResult;
      import flash.data.SQLStatement;
      import flash.data.SQLMode;
      import flash.events.SQLErrorEvent;
      import flash.events.SQLEvent;
      import flash.filesystem.File;
      import fl.controls.*;

      var conn:SQLConnection = new SQLConnection();
      var dbFile:File = File.applicationDirectory.resolvePath("Playbook.db");

      conn.open(dbFile, SQLMode.UPDATE);
      trace("the database opened successfully");
      catch (error:SQLError)
      trace("Error message:", error.message);
      trace("Details:", error.details);

      // create the SQL statement
      var selectStmt:SQLStatement = new SQLStatement();
      selectStmt.sqlConnection = conn;

      // define the SQL text
      var sql:String =
      "SELECT ID, inst_title, inst_desc " +
      "FROM install";
      selectStmt.text = sql;


      var result = selectStmt.getResult();
      var numResults = result.data.length;

      for (var i = 0; i < numResults; i++)
      var row = result.data ;

      var myText = "";
      myText += "<p><b>" + row.ID;
      myText += "</b></p>";
      myText += "<p><b><a href=' http://www.adobe.com'>" + row.inst_title;
      myText += "</a></b></p>";
      myText += "<p>" + row.inst_desc;

      var myTextArea:TextArea = new TextArea();
      myTextArea.setSize(350, 350);
      myTextArea.move(10, 10);
      myTextArea.htmlText = myText;

      var taFiles:TextArea = new TextArea();
      taFiles.setSize(350, 350);
      taFiles.move(400, 10);
      taFiles.appendText(myText + "\n\n");


      catch (error)
      // Information about the error is available in the
      // error variable, which is an instance of
      // the SQLError class.