Solved

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

Posted on 2009-05-20
2
545 Views
Last Modified: 2012-08-13
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

0
Comment
Question by:DataGranger
2 Comments
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 24432257
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
 

Accepted Solution

by:
DataGranger earned 0 total points
ID: 24436247
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

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now