6 Replies Latest reply on Feb 25, 2010 10:13 AM by thewrsthe

    SQLite openAsync & loadSchema

    thewrsthe

      Hi,

       

      I'm having trouble gathering schema information from a database i've opened asyncronously.

       

      I get the error Error #2044: Unhandled SQLErrorEvent:. errorID=3115, operation=schema , message=Error #3115: SQL Error. , details=No schema objects in database 'main' were found

       

      I do not encounter this problem when using syncronous database with open().

       

      Database contains one table with around 10,000 records. Standard SQL querys against the database work fine, I just cant get the schema

       

      Here's my code.

       

      package com.roleready {
          import flash.data.SQLConnection;
          import flash.data.SQLMode;
          import flash.data.SQLSchema;
          import flash.errors.SQLError;
          import flash.events.SQLEvent;
          import flash.filesystem.File;
          import flash.net.Responder;
         
          public class DBTest {
             
              private var dbFile:File = File.applicationStorageDirectory.resolvePath('roleready.db3');
             
              private var conn:SQLConnection;
             
              private var _responder:Responder;
             
              public function DBTest():void {
                  _responder = new Responder(resultEventHandler, errorEventHandler);
                  conn = new SQLConnection();
                  conn.openAsync(dbFile, SQLMode.UPDATE, _responder);
              }
             
              private function resultEventHandler(event:SQLEvent):void {
                  switch(event.type){
                      case SQLEvent.OPEN:        // database opened
                          trace("Database connected");
                          conn.addEventListener(SQLEvent.SCHEMA, resultEventHandler);
                          conn.loadSchema();
                          break;
                      case SQLEvent.SCHEMA:    // schema received
                          trace("Got db schema");
                          break;
                      default:
                          trace("Unhandled result event:", event.type);
                          break;
                  }
              }
             
              private function errorEventHandler(error:SQLError):void {
                  trace(error);
              }
             
          }
      }

       

      Any suggestions?

        • 1. Re: SQLite openAsync & loadSchema
          -jw

          Using the code provided, I am unable to reproduce this issue with an internal build of 2.0.   What version of the runtime are you using?  Can you post your database file for testing?

           

          Thanks,

          jw

          • 2. Re: SQLite openAsync & loadSchema
            thewrsthe Level 1


            I believe I am using AIR 1.5.3 with flex_sdk_4.0.0.13875.

             

            Database file is available from: http://www.billybob.eu/roleready.db3

             

            I'll set up another SDK for use with AIR 2b2 and test

             

            *EDIT*

             

            Running with AIR 2 beta2 and getting similar error: Error #2044: Unhandled error:. text=Error #3115: SQL Error.

             

            then

             

            Error #2044: Unhandled SQLErrorEvent:. errorID=3115, operation=schema , message=Error #3115: SQL Error. , details=No schema objects in database 'main' were found.

             

            Executing code was unchanged.

            • 3. Re: SQLite openAsync & loadSchema
              -jw Level 1

              With that db file I can reproduce the issue.  This is definitely a bug.  It is dispatching an error even though the schema is actually there, you can get at the schema even after the error is dispatched by using the getSchemaResult() method of the connection.  The table structure is hitting an edge case in the core code. A guess at a workaround based on what I am seeing is that if you just add another table or two to the db you won't get the error anymore.

               

              Hope that helps.

              jw

              1 person found this helpful
              • 4. Re: SQLite openAsync & loadSchema
                thewrsthe Level 1

                Thanks for the info, jw

                 

                Could you elaborate a little on 'The table structure is hitting an edge case in the core code.'

                 

                I understand this may be a bug in AIR SQLite, but i'm curious to know why my table structure might cause this apparently rare problem.

                 

                I'm not too familiar with the bug reporting process, could you perhaps provide advice on bringing this issue to the attention of Adobe.

                 

                I am yet to try your suggestions, will report back soon.

                • 5. Re: SQLite openAsync & loadSchema
                  -jw Level 1

                  Sure I can elaborate a little bit.  There is a an algorithm that we use to break data up into chunks when a connection is in async mode.  The size of the schema in your database is just the right size to tickle a bug that causes an error to be dispatched even though everything succeeded.  I have already logged a bug for this issue and have a local fix.  No guarantees which release the fix will land in though.

                   

                  Did you try the workaround?

                  jw

                  • 6. Re: SQLite openAsync & loadSchema
                    thewrsthe Level 1

                    Thanks for the additional info.

                     

                    I've added additional tables to the database as you suggested. The SQLEvent.SCHEMA event is now being dispatched properly with no unexpected errors reported.

                     

                    Your help has been greatly appreciated. Best of luck with future releases!