Adrian Johnson
Adrian Johnson

Reputation: 181

Error when accessing SQLite DB in Adobe Air app

I'm getting an error accessing a table in a SQLite database within my Adobe Air. I'm using Aptana to code it on a Windows 7 machine.

The main function contains:

SetupDB();
dbQuery = new air.SQLStatement();
dbQuery.sqlConnection = db;
dbQuery.text = "SELECT id FROM room_packs";  // Error occurs here

try {  
dbQuery.execute();  
} catch (error) {  
air.trace("Error retrieving notes from DB:", error);  
air.trace(error.message);  
}

and the SetupDB function is:

function SetupDB() {  
    var dbFile = air.File.applicationStorageDirectory.resolvePath("fyw.db");
    air.trace(dbFile.nativePath + " is where my file is stored");

    try  
    {
      db.open(dbFile);
      air.trace("Database is open!");
    }  
    catch (error)  
    {  
          air.trace("DB error:", error.message);  
          air.trace("Details:", error.details);  
    }  
 }

The trace telling me where my file is stored is printed ok, as is the line "Database is open!". The error message I get is:

Error retrieving notes from DB: SQLError: 'Error #3115: SQL Error.', details:'no such table: 'room_packs'', operation:'execute', detailID:'2013'

As far as I know I'm doing everything correctly (according to all the tutorials on the net). The SQLite database is located in the root folder of the project as well as within the LocalSource folder in Application Data. Where am I going wrong?

Thanks,

Adrian

Upvotes: 0

Views: 682

Answers (2)

Vinoth Jayaprakash
Vinoth Jayaprakash

Reputation: 11

I don't see a CREATE TABLE statement for your table 'room_packs'. You are receiving an error because you are trying to query a table which doesn't even exists. First create a table 'room_packs' before using the SELECT statement.

Upvotes: 1

Adrian Johnson
Adrian Johnson

Reputation: 181

Managed to sort it. Some of the examples I'd found weren't complete pieces of code. Managed to find a fuller sample so was able to access the data properly.

Upvotes: 0

Related Questions