2 Replies Latest reply on Feb 4, 2011 1:33 PM by chris.campbell

    SQLErrorEvent problem

    Kristin95762 Level 1

      Not sure this is a performance issuer per se, but can't find an approriate venue.


      This is producing an error when I SELECT on a value which is not present in the database.


      Let's say, for simplicity, that my database table has columns authors.lName and authors.fName


      If I don't have a name that begins with some letter (let's say 'z') the program throws an error. The problem is that it's NOT using the error handler that is established. If I clear the default error window out, I can continue on with my program, but the default window is cryptic.


      Everything works fine until I enter a value that doesn't exist in the table. Ultimately I would just like the error handling to occur in the background and have the result return nothing to the listbox.


      Yes, this output appears in the output panel:


      TypeError: Error #1009: Cannot access a property or method of a null object reference.

      at testinputbox3_fla::MainTimeline/readResultHandler()[testinputbox3_fla.MainTimeline::frame 1:58]


      But I know it's bypassing my errorHandler because my literals are not in the error statement. i.e., my errorHandler function specifies trace("Error message: ", event.error.message);


      Of course, if I delete my error routine, the error outputs to the panel anyway.


      I feel I am in some way prevented from capturing this error so that I can handle it.


      what should I do?


      Here's my code:


      import flash.data.SQLConnection;

      import flash.data.SQLMode;

      import flash.data.SQLResult;

      import flash.events.SQLEvent;

      import flash.filesystem.File;

      import fl.data.DataProvider;

      import fl.controls.List;

      import flash.events.KeyboardEvent;

      import flash.events.Event;

      import flash.events.MouseEvent;

      import flash.net.URLRequest;

      import flash.display.Loader;

      import flash.display.NativeWindow;

      import flash.system.Capabilities;

      import flash.text.TextField;

      import flash.errors.SQLError;

      import flash.events.SQLErrorEvent;


      var appWindow:NativeWindow = this.stage.nativeWindow;


      appWindow.x = (Capabilities.screenResolutionX - appWindow.width) / 2;

      appWindow.y = (Capabilities.screenResolutionY - appWindow.height) / 2;



      var conn:SQLConnection = new SQLConnection();

      conn.addEventListener(SQLEvent.OPEN, readFromDatabase);

      conn.addEventListener(SQLErrorEvent.ERROR, errorHandler);


      var dbFile:File = File.desktopDirectory.resolvePath("tarot.db");

      conn.openAsync(dbFile, SQLMode.UPDATE);



      txtIn.addEventListener(Event.CHANGE, changeHandler);

      var txtIn:TextField;

      txtIn.stage.focus = txtIn;


      var txtOut:String = "a";


      function readFromDatabase(event:Event):void


      var selectStmt:SQLStatement = new SQLStatement();

      selectStmt.sqlConnection = conn;


      // register listeners for the result and failure (status) events

      selectStmt.addEventListener(SQLEvent.RESULT, readResultHandler);

      selectStmt.addEventListener(SQLErrorEvent.ERROR, errorHandler);


      // define the SQL text;

      selectStmt.text = "SELECT * FROM authors WHERE lName LIKE '" + txtOut + "%'";


      // execute the statement




      function readResultHandler(event:SQLEvent):void


      var result:SQLResult = event.target.getResult();

      var numResults:int = result.data.length;


      for (var i:int = 0; i < numResults; i++)


      var row:Object = result.data[i];

      var dataOut:String;


      dataOut = row.lName + ", " + row.fName;





      authorName.text = row.lName;




      function changeHandler(e:Event):void


      if (0 < txtIn.text.length)



      txtOut = txtIn.text;









      function errorHandler(event:SQLErrorEvent):void


      trace("Error message: ", event.error.message);

      trace("Details: ", event.error.details);