7 Replies Latest reply on Jun 16, 2011 10:40 AM by Kristin95762

    need help understanding an example in Flex 4 Language Reference: flash.data.sqlstatement

    Kristin95762 Level 1

      I don't understand how to use the example in Flash Builder. I read the link concerning this, but it's still unclear.


      1) Is this example a single file, or should the class definition be separate? I ask because I don't see any import statements at all, which makes me wonder how it would work.


      2) does init() act as the automatic entry point for this code, or is this function called from some unseen event?


      3) does dbStatement.itemClass = Employee represent the link between the main app and the class file?


      I've been looking all over for a solution to my problem in that I have 8 or 10 querries to a sqlite db in my main application and I would really like to move each to their own file, but I don't understand how to reference them from the main app, or how to share the results with the main app. I was hoping this was what I'm looking for.


      // Employee class definition
          public class Employee
              public var name:String;
              public var ssn:String;
              public var id:uint;
              public override function toString():String
                  return "id: "+ id.toString() + " name: " + name + " ssn: " + ssn;
      // using the Employee class as SQLStatement.itemClass
      var conn:SQLConnection;
      var dbStatement:SQLStatement;
      function init():void
          conn = new SQLConnection();
          conn.addEventListener(SQLEvent.OPEN, connOpenHandler);
          dbStatement = new SQLStatement();
          dbStatement.sqlConnection = conn;
          dbStatement.text = "SELECT id, name, ssn FROM employees";
          dbStatement.itemClass = Employee;
          var dbFile:File = new File(File.separator + "employee.db");
      function connOpenHandler(event:SQLEvent):void
          dbStatement.addEventListener(SQLEvent.RESULT, resultHandler);
      function resultHandler(event:SQLEvent):void
          var result:SQLResult = dbStatement.getResult();
          if (result != null)
              var emp:Employee;
              var numRows:int = result.data.length;
              for (var i:int = 0; i < numRows; i++)
                  emp = result.data[i];