9 Replies Latest reply on Aug 22, 2007 2:30 AM by prokiprich

    SQL example doesn't work

    JenLarkin
      I used the code on this page as a basis for my test app:
      http://livedocs.adobe.com/labs/air/1/devappshtml/SQL_16.html#1088484

      I made a new AIR project, copied the xmlns code from a working air app into the mxml file, put in
      <mx:Script>
      <![CDATA[
      var conn = new air.SQLConnection();
      ... [rest of the code sample from the docs]
      ]]>
      </mx:Script>

      When I tried to run as an AIR app, I got a warning that there were errors and the first error that was marked in the sidebar with a red circle with an x in it said "1120: access undefined property of air." The rest of the errors were basically things that followed from the lack of recognition of "air."

      Do I need to import something? I'm confused.
        • 1. Re: SQL example doesn't work
          rgrzywinski Level 1
          That seems to be an out-of-date example. Drop the 'air' prefixes and use the following for an example:

          http://livedocs.adobe.com/labs/air/1/devappsflex/help.html?content=SQL_08.html#1084881
          • 2. Re: SQL example doesn't work
            JenLarkin Level 1
            Well, that example is better but it still doesn't work. Now it displays the 1120: Access of undefined property conn. message on these two lines:
            conn.addEventListener(SQLEvent.OPEN, openHandler);
            conn.addEventListener(SQLErrorEvent.ERROR, errorHandler);

            1120:Access of undefined property dbFile on:
            conn.open(dbFile, false);

            and two errors that I see in the problems window but are not marked in the code:
            1120: Access of undefined property errorHandler
            1120: Access of undefined property openHandler
            • 3. SQL example doesn't work
              rgrzywinski Level 1
              Just how are you doing this? You have to put everything after the "import" statements into a function or something like that. C&P in the code in here -exactly- as you're trying it and we'll see what we can see.
              • 4. Re: SQL example doesn't work
                rgrzywinski Level 1
                Let's cut to the chase:

                1. create a new AIR project
                2. the main *.mxml file should be open
                3. paste in the code below (overwriting -everything- in the file)
                4. run it
                5. start playing with it (since it worn't work immediately). For example, change "false" to "true/*autocreate*/".
                6. No, it's not clear in the examples (if you've never done this before) that parts of the code go in method bodies and other parts go elsewhere.

                <?xml version="1.0" encoding="utf-8"?>
                <mx:WindowedApplication xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute"
                creationComplete="creationCompleted()">
                <mx:Script>
                <![CDATA[
                import flash.data.SQLConnection;
                import flash.events.SQLErrorEvent;
                import flash.events.SQLEvent;
                import flash.filesystem.File;

                private function creationCompleted():void {
                var conn:SQLConnection = new SQLConnection();
                conn.addEventListener(SQLEvent.OPEN, openHandler);
                conn.addEventListener(SQLErrorEvent.ERROR, errorHandler);

                var dbFile:File = File.applicationStorageDirectory.resolve("DBSample.db");

                conn.open(dbFile, false);

                function openHandler(event:SQLEvent):void {
                trace("the database was opened successfully");
                }
                function errorHandler(event:SQLErrorEvent):void {
                trace("Error code:", event.error.code);
                trace("Details:", event.error.message);
                }
                }
                ]]>
                </mx:Script>
                </mx:WindowedApplication>
                • 5. Re: SQL example doesn't work
                  JenLarkin Level 1
                  I will try this on Thursday. I have a lecture to give on AIR tomorrow and I had to skip this part of the app I'm trying to build for it. Of course, plan B isn't working either so I'm having to skip to C. I will report the other issue after the lecture.
                  • 6. Re: SQL example doesn't work
                    Handycam Level 1
                    Thanks for the code. It's real frustrating when you read all the docs, and the docs are wrong! Your code did not generate any errors.

                    But I have a question: it runs in the debugger but says it can't find my db file:

                    Error code: cannotOpen
                    Details: Database file '/' does not exist.

                    Where should I put my physical DB file (called, in my case, "FWFileIndex.db")? Right now it's in the same directory as the MXML file.

                    Thanks.
                    • 7. Re: SQL example doesn't work
                      Jeff Swartz Level 3
                      The documentation you are looking at is for developing HTML-based applications. (The air prefixes are used in JavaScript in such apps.) You should look at the following Flex-specific docs:

                      http://livedocs.adobe.com/labs/air/1/devappsflex/SQL_16.html

                      Also, the docs describe File.applicationStorageDirectory here:

                      http://livedocs.adobe.com/labs/air/1/devappsflex/Filesystem_05.html#1028268

                      The code creates the database file--you need not create it outside of the application: conn.open(dbFile)

                      You can find the path to the database file via the following code:

                      • 8. Re: SQL example doesn't work
                        JenLarkin Level 1
                        When I was working on this, the first link was the documentation linked on the labs site as the Flex documentation, and the code looks remarkably like the code in the O'Reily Apollo book, which is the Flex book that I was told last week in Vancouver was 95% accurate. I didn't laugh loud enough for anyone else to hear.

                        I also compared it to the HTML documentation linked from the site at that time and that was a third document. Since it was clear that the labs link was incorrect, I opened it several times and compared it and that was definitely the documentation linked as the Flex documentation. I even opened it from different IP address one thaton Adobe's guest network.

                        I just don't want there to be any confusion about why people are looking at the documentation at the link I provided in the original message.

                        Technical documentation is for people who don't know better and I certainly can't be expected to know by the URL.

                        In subsequent versions of the documentation, please denote whether or not the documentation is for the Flex version or the HTML/JS version in the header of the pages so we can at least spot a problem on the same page that we are looking at. Having it on the intro page isn't helpful for online documentation.

                        Thanks
                        • 9. Re: SQL example doesn't work
                          prokiprich
                          HI There !

                          I tried to find a problem with the DB, and i didnt experiece any error

                          This is my example how everything is right: ______________________________________________________________

                          <?xml version="1.0" encoding="utf-8"?>
                          <mx:WindowedApplication xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initAPP();">
                          <mx:Script>
                          <![CDATA[
                          import flash.data.SQLConnection;
                          import flash.events.SQLErrorEvent;
                          import flash.events.SQLEvent;
                          import flash.filesystem.File;
                          import mx.controls.Alert;


                          [Bindable]
                          public var conn:SQLConnection = new SQLConnection();

                          [Bindable]
                          public var dbFile:File = File.applicationStorageDirectory.resolve("DBSample.db");


                          private function initAPP():void {
                          conn.open(dbFile);

                          conn.addEventListener(SQLEvent.OPEN, openHandler);
                          conn.addEventListener(SQLErrorEvent.ERROR, errorHandler);

                          }

                          // var dbFile:File = File.applicationStorageDirectory.resolve("DBSample.db");

                          public function openHandler(event:SQLEvent):void{
                          Alert.show("the database was created successfully");
                          }

                          public function errorHandler(event:SQLErrorEvent):void{
                          Alert.show("Error code:", event.error.code);
                          Alert.show("Details:", event.error.message);

                          }
                          ]]>
                          </mx:Script>
                          </mx:WindowedApplication>