Whats the problem with this connection from Javasript to SQLITE on Adobe Air?

The code from the SQLite connection and the select i taked from the Adobe Air HTML/Javascript manual, but im pretty confused.

The connection to the DB works, but when i execute the datosBD() function for the select statement from the Adobe Air Introspector, well that doesnt work.

And in the debug window it tells me the next:
"Error message: Error #3115: SQL Error.
Details: no such table: 'prueba'.


I know the connection its open, and i know my db works, because i opened it with sqliteadmin, sqlite Maestro, and SQLite Professional and i executed some SELECT querys like this.

SELECT * FROM prueba
SELECT Nombre, Paterno FROM prueba.

I just dont know why from the Adobe Air it keeps telling me theres an error.

Thanks in advance, and sorry for my bad english as im from Mexico.

Greetings.
var conn = new air.SQLConnection(); 
conn.addEventListener(air.SQLEvent.OPEN, openHandler); 
conn.addEventListener(air.SQLErrorEvent.ERROR, errorHandler); 
var dbFile = air.File.applicationStorageDirectory.resolvePath("sist.db"); 
conn.openAsync(dbFile, air.SQLMode.READ); 
function openHandler(event) 
{ 
    air.trace("the database opened successfully"); 
	alert('Conectado');
 
 
} 
function errorHandler(event) 
{ 
    air.trace("Error message:", event.error.message); 
    air.trace("Details:", event.error.details); 
alert('No conectado');
 
}
function datosBD(){
// ... create and open the SQLConnection instance named conn ... 
// create the SQL statement 
var selectStmt = new air.SQLStatement(); 
selectStmt.sqlConnection = conn; 
// define the SQL text 
var sql =  
    "SELECT Nombre, Paterno " +  
    "FROM prueba"; 
selectStmt.text = sql; 
// register listeners for the result and error events 
selectStmt.addEventListener(air.SQLEvent.RESULT, selectResult); 
selectStmt.addEventListener(air.SQLErrorEvent.ERROR, selectError); 
// execute the statement 
selectStmt.execute(); 
}
 
function selectResult(event) 
{ 
    // access the result data 
    var result = selectStmt.getResult(); 
    var numRows = result.data.length; 
    for (i = 0; i < numRows; i++) 
    { 
        var output = ""; 
        for (columnName in result.data[i]) 
        { 
            output += columnName + ": " + result.data[i][columnName] + "; "; 
        } 
        air.trace("row[" + i.toString() + "]\t", output); 
    } 
} 
function selectError(event) 
{ 
    air.trace("Error message:", event.error.message); 
    air.trace("Details:", event.error.details); 
}
 
</script>

Open in new window

DataGrangerAsked:
Who is Participating?
 
DataGrangerConnect With a Mentor Author Commented:
Well i just found the answer, when you are working with sqlite on Adobe air,  and the Database its local and its prepopulated on the folder of your files. You have to copy the database to another file, because its read only.

As the manual says:

"Like all files that are included in an AIR package, a bundled database file is installed in the application directory (the directory represented by the File.applicationDirectory property). However, files in that directory are read only. Use the file from the AIR package as a template database. The first time a user runs the application, copy the original database file into the users application storage directory (or another location), and use that database within the application."

So once again, I read all the manual(RTFM),  and find my answer.

I attach the code that i used to copy the database prepopulated, im used sync DB.

Thanks in advance.

 var dbFile = air.File.applicationStorageDirectory.resolvePath("notes.db");
 
 //In production, uncomment the if block to maintain the database.
 if (!dbFile.exists) {
   var dbTemplate = air.File.applicationDirectory.resolvePath("sist.db");
   dbTemplate.copyTo(dbFile, true);  
 }

Open in new window

0
 
ChristoferDutzCommented:
I think the message says all ... there is no such table. One thing you should check though, is if you eventually need to add a shema. In MySQL for example, if you don't logon to the db using a default shema, then you need to add it to the table name. So maybe your Statement should be :
"SELECT Nombre, Paterno  FROM schemaname.prueba"
0
All Courses

From novice to tech pro — start learning today.