Skip to main content
Participant
July 11, 2011
Answered

Adobe Air for iOS - SQLError: 'Error #3115' no such table

  • July 11, 2011
  • 1 reply
  • 6961 views

I am developing Adobe Air application for iOS with sqlite on it. When running on my local machine, it worked like charm (add, edit & delete). Unfortunately, when tried running on iPAD, it gives me the following error:

SQLError: 'Error #3115', details:'no such table: 'tblEmploye'', operation:'execute', detailID:'2013'

Here's my code when opening the sqlite database: ** data file is saved on the current application directory where all the files are stored:

      
        exampleDBFile = File.documentsDirectory.resolvePath("mydb.db");


        if (exampleDBFile==null || !exampleDBFile.exists) {
            MovieClip(root).mcSong.visible = false;
            MovieClip(root).mcAlert.visible = true;
            MovieClip(root).mcAlert.enabled = true;
            MovieClip(root).mcAlert.txtErrorMessage.text = "Database not found";
        }
        exampleDB = new SQLConnection();
       
        exampleDB.addEventListener(SQLEvent.OPEN, onExampleDBOpened);
        exampleDB.addEventListener(SQLErrorEvent.ERROR, onExampleDBError);
       
        //exampleDB.openAsync(exampleDBFile);
        exampleDB.open(exampleDBFile);

I also tried using the following but still no luck

exampleDBFile = File.applicationDirectory.resolvePath("mydb.db");            

when using this, i receive a different error : Error:Error #3104

And heres the code for adding new entries

        
        sqlInsert = "insert into tblLyrics (empName, empDesc) values
                    ('"+ strReplace(txtSearchMe.text, "'", "") + "','"+ strReplace(txtContent.text,"'","") +"')";
        dbStatement.text = sqlInsert;       
        dbStatement.addEventListener(SQLEvent.RESULT, onDBStatementInsertResult);       
        dbStatement.execute();

Hoping for your advice....

This topic has been closed for replies.
Correct answer blazejewicz

Hi,

@uxavenue

to add something to Sanika's post:

- on iOS your application directory is "read-only" (at least when using native applicaiton) - so resources in application directory (in terminology of Air SDK - not iOS SDK) cannot be modified/written/updated

- you could ship already created sqlite database file with your application but it should be copied into application writable directory - e.g. to documents. This directory can be accessed via:

File.documentsDirectory

- so when your application starts you could do following:

1) construct path to documents directory database path

2) check if database in that path exists (if File exists)

3) if file does not exists yet either copy it into that path from application resources directory (where you bundle it when building project) OR create new empty database using all those CREATE table and then INSERT statements required to create new fresh copy of database

4) on each next startup if checking if file exists at #2 skip database creation/copy and simply start using it.

kind regards,

Peter

1 reply

Participating Frequently
July 11, 2011

Hi,

#1

the first error indicates that your SQL statement contains table name that does not exists in database schema - that's hard to tell based on your code snippet as it uses different table name "tblLyrics" though

#2

the second error simply states that operation cannot be executed on non-opened connection. That means that your connection to database failed: either path is wrong and there is database file found or there is other reason why connection has not been established.

So to isolate errors first try to investigate connection error.

regards,

Peter

uxavenueAuthor
Participant
July 12, 2011

Thank you pete!

Anyway regarding #1, sorry, its tblEmployee.

As told from my previous message, its working fine when running the application locally on my desktop (add, edit delete...), but once ported in iTunes for iPAD, I receive this errors.  When running the application on iPAD, all of the functionalities are working fine, except when manipulating the sqlite db (like adding). I was thinking maybe iOS doesn’t support sqlite or maybe theres no write permission by default. Im really new with iOS and I really don’t know the do's and don’t for adobe air iOS development.

Participating Frequently
July 12, 2011

Hi,

I am sorry you are facing this issue. Is the code that you posted all that you are doing? It is missing a few things:

1) You are not creating the dbFile and the table tblEmployee. Do they already exist on your desktop? On device, you would need to create them.

2) dbStatement.SQLConnection property is not set anywhere.

The following sample code is from http://help.adobe.com/en_US/air/reference/html/flash/data/SQLConnection.html. Could you try and see if it works for you?

package
{
     import flash.data.SQLConnection;
     import flash.data.SQLResult;
     import flash.data.SQLStatement;
     import flash.display.Sprite;
     import flash.events.SQLErrorEvent;
     import flash.events.SQLEvent;
     import flash.filesystem.File;
     
     public class MultipleInsertTransactionExample extends Sprite
     {
          private var conn:SQLConnection;
          private var insertEmployee:SQLStatement;
          private var insertPhoneNumber:SQLStatement;
          private var dbFile:File
          
          public function MultipleInsertTransactionExample():void
          {
               // define where to find the database file
               //var appStorage:File = File.applicationDirectory;
          dbFile = new File(File.documentsDirectory.nativePath + File.separator + "ExampleDatabase.db");
               
               // open the database connection
               conn = new SQLConnection();
               conn.addEventListener(SQLErrorEvent.ERROR, errorHandler);
               conn.addEventListener(SQLEvent.OPEN, openHandler);
               conn.openAsync(dbFile);
          }
          
          // Called when the database is connected
          private function openHandler(event:SQLEvent):void
          {
               conn.removeEventListener(SQLEvent.OPEN, openHandler);
               
               // start a transaction
               conn.addEventListener(SQLEvent.BEGIN, beginHandler);
               conn.begin();
          }
          
          // Called when the transaction begins
          private function beginHandler(event:SQLEvent):void
          {
               conn.removeEventListener(SQLEvent.BEGIN, beginHandler);
               
               // create and execute the first SQL statement:
               // insert an employee record
               var createEmployees:SQLStatement = new SQLStatement();
               createEmployees.sqlConnection = conn;
               createEmployees.text =
                    "CREATE TABLE IF NOT EXISTS employees(lastName, firstName, email, birthday) ";
               createEmployees.execute();
               insertEmployee = new SQLStatement();
               insertEmployee.sqlConnection = conn;
               insertEmployee.text = 
                    "INSERT INTO employees (lastName, firstName, email, birthday) " + 
                    "VALUES (:lastName, :firstName, :email, :birthday)";
               insertEmployee.parameters[":lastName"] = "Smith";
               insertEmployee.parameters[":firstName"] = "Bob";
               insertEmployee.parameters[":email"] = "bsmith@example.com";
               insertEmployee.parameters[":birthday"] = new Date(1971, 8, 12);
               
               insertEmployee.addEventListener(SQLEvent.RESULT, insertEmployeeHandler);
               insertEmployee.addEventListener(SQLErrorEvent.ERROR, errorHandler);
               
               insertEmployee.execute();
          }
          
          // Called after the employee record is inserted
          private function insertEmployeeHandler(event:SQLEvent):void
          {
               insertEmployee.removeEventListener(SQLEvent.RESULT, insertEmployeeHandler);
               insertEmployee.removeEventListener(SQLErrorEvent.ERROR, errorHandler);
               
               // Get the employee id of the newly created employee row
               var result:SQLResult = insertEmployee.getResult();
               var employeeId:Number = result.lastInsertRowID;
               
               // Add a phone number to the related phoneNumbers table
               
               var createTab:SQLStatement = new SQLStatement();
               createTab.sqlConnection = conn;
               createTab.text = 
                    "CREATE TABLE IF NOT EXISTS phoneNumbers(employeeId, type, number)";
               createTab.execute();
               insertPhoneNumber = new SQLStatement();
               insertPhoneNumber.sqlConnection = conn;
               insertPhoneNumber.text =
                    "INSERT INTO phoneNumbers (employeeId, type, number) " +
                    "VALUES (:employeeId, :type, :number)";
               insertPhoneNumber.parameters[":employeeId"] = employeeId;
               insertPhoneNumber.parameters[":type"] = "Home";
               insertPhoneNumber.parameters[":number"] = "(555) 555-1234";
               
               insertPhoneNumber.addEventListener(SQLEvent.RESULT, insertPhoneNumberHandler);
               insertPhoneNumber.addEventListener(SQLErrorEvent.ERROR, errorHandler);
               
               insertPhoneNumber.execute();
          }
          
          // Called after the phone number record is inserted
          private function insertPhoneNumberHandler(event:SQLEvent):void
          {
               insertPhoneNumber.removeEventListener(SQLEvent.RESULT, insertPhoneNumberHandler);
               insertPhoneNumber.removeEventListener(SQLErrorEvent.ERROR, errorHandler);
               
               // No errors so far, so commit the transaction
               conn.addEventListener(SQLEvent.COMMIT, commitHandler);
               conn.commit();
          }
          
          // Called after the transaction is committed
          private function commitHandler(event:SQLEvent):void
          {
               conn.removeEventListener(SQLEvent.COMMIT, commitHandler);
               
               trace("Transaction complete");
          }
          
          // Called whenever an error occurs
          private function errorHandler(event:SQLErrorEvent):void
          {
               // If a transaction is happening, roll it back
               if (conn.inTransaction)
               {
                    conn.addEventListener(SQLEvent.ROLLBACK, rollbackHandler);
                    conn.rollback();
               }
               
               trace(event.error.message);
               trace(event.error.details);
          }
          
          // Called when the transaction is rolled back
          private function rollbackHandler(event:SQLEvent):void
          {
               conn.removeEventListener(SQLEvent.ROLLBACK, rollbackHandler);
               
               // add additional error handling, close the database, etc.
          }
     }
}
Thanks,

Sanika