2 Replies Latest reply on Jan 19, 2009 10:55 AM by jdesko

    loadSchema and getSchemaResult

      Through Air 1.5/Flash CS4 I created a SQLLite database, table, and fields. I am trying to view the layout of this database, using loadSchema and getSchemaResult. Below is the basic code, but I am lacking something since my trace is only showing [object SQLSchemaResult]. The FireFox add-on verifies the databases content is there that I created. Thanks in advance for any help.

      import flash.display.Sprite;
      import flash.display.StageScaleMode;

      import flash.data.SQLConnection;
      import flash.data.SQLStatement;
      import flash.data.SQLResult;
      import flash.events.SQLErrorEvent;
      import flash.events.SQLEvent;
      import flash.filesystem.File;

      public class myApp extends Sprite
      var conn:SQLConnection;
      var file:File;
      var dbFile:File;
      var sqlState:SQLStatement;
      var sqlResult:SQLResult;
      var sql:String;

      public function myApp()
      conn = new SQLConnection();
      conn.addEventListener(SQLEvent.OPEN, openHandler)
      conn.addEventListener(SQLErrorEvent.ERROR, errorHandler)

      dbFile = File.documentsDirectory.resolvePath("myFile/myFile.db");
      private function openHandler(event:SQLEvent)
      conn.loadSchema(null, null);
      conn.addEventListener(SQLEvent.SCHEMA, connSchema)
      private function errorHandler(event:SQLErrorEvent)
      trace("file not found")
      private function connSchema(event:SQLEvent)
      var db = conn.getSchemaResult();

        • 1. Re: loadSchema and getSchemaResult
          flexstone Level 1
          Once you have the Schema object you have to parse it into a human readable form.......Its not like a "describe" from mySQL or SQL

          here is a script that will do that "T" is your table,

          public function describeTable(T,dbfile:File):String{

          var newConn:SQLConnection = new SQLConnection()

          var schemaResult:SQLSchemaResult = newConn.getSchemaResult();
          var schema=schemaResult.tables

          for each(var tab in schema){
          var dump = tab.sql

          return dump;

          • 2. Re: loadSchema and getSchemaResult
            jdesko Level 2
            Thanks flexstone; and thanks much for the quick response, that helps.