Sunday, April 4, 2010

Actionscript 3 - AIR - SQLite: no such...

Hello everybody.

I have a custom class, where I try to create a database, and select a table named list... everything seems work well, but when I try to select the table list, I got the next message error: Error #3115: SQL Error., details: no such table: list... but in the code, I do create the table

My custom class is:

package com.actionscript.class.sql{

聽聽聽 import flash.data.*;
聽聽聽 import flash.display.MovieClip;
聽聽聽 import flash.filesystem.File;
聽聽聽 import fl.data.DataProvider;
聽聽聽 import flash.events.SQLErrorEvent;
聽聽聽 import flash.events.Event;
聽聽聽 import flash.events.SQLEvent

聽聽聽 public class dataBase extends MovieClip {

聽聽聽聽聽聽聽 public var db:File;
聽聽聽聽聽聽聽 public var conn:SQLConnection;
聽聽聽聽聽聽聽 public var dp:DataProvider;
聽聽聽聽聽聽聽 public const tabla:String=''list'';
聽聽聽聽聽聽聽 public var dodb:Boolean;
聽聽聽聽聽聽聽 public var ruta:MovieClip;

聽聽聽聽聽聽聽 public function dataBase(lruta):void {

聽聽聽聽聽聽聽聽聽聽聽 ruta=lruta;
聽聽聽聽聽聽聽聽聽聽聽 db=File.applicationStorageDirectory.resolvePath(''mydb.db'');
聽聽聽聽聽聽聽聽聽聽聽 conectar();
聽聽聽聽聽聽聽聽聽聽聽 if (!db.exists) {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 crear();
聽聽聽聽聽聽聽聽聽聽聽 } else {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 existe();
聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽 private function conectar() {

聽聽聽聽聽聽聽聽聽聽聽 conn=new SQLConnection();
聽聽聽聽聽聽聽聽聽聽聽 conn.addEventListener(SQLEvent.OPEN, onOpen);
聽聽聽聽聽聽聽聽聽聽聽 conn.addEventListener(SQLErrorEvent.ERROR, onError);
聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽 private function crear() {

聽聽聽聽聽聽聽聽聽聽聽 conn.openAsync(db);
聽聽聽聽聽聽聽聽聽聽聽 dodb=true
聽聽聽聽聽聽聽聽聽聽聽 ;
聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽 private function existe() {

聽聽聽聽聽聽聽聽聽聽聽 conn.openAsync(db);

聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽 private function onOpen(e:SQLEvent) {

聽聽聽聽聽聽聽聽聽聽聽 if (dodb) {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 var sentencia:SQLStatement= new SQLStatement();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 sentencia.sqlConnection=conn;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 sentencia.addEventListener(SQLErrorEvent.ERROR, onError);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //sentencia.addEventListener(SQLEvent.RESULT, onResultado);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 var sql:String=''CREATE TABLE '''+tabla+''' ('';
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 sql+=''id INTERGER PRIMARY KEY AUTOINCREMENT,'' ;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 sql+=''nombre TEXT,'';
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 sql+=''ruta TEXT'';
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 sql+='')'';
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 sentencia.text=sql;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 sentencia.execute();
聽聽聽聽聽聽聽聽聽聽聽 } else {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 getData();
聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽 private function getData() {

聽聽聽聽聽聽聽聽聽聽聽 var consulta:SQLStatement= new SQLStatement();
聽聽聽聽聽聽聽聽聽聽聽 consulta.sqlConnection=conn;
聽聽聽聽聽聽聽聽聽聽聽 consulta.addEventListener(SQLErrorEvent.ERROR, onError);
聽聽聽聽聽聽聽聽聽聽聽 consulta.addEventListener(SQLEvent.RESULT, onResultado);
聽聽聽聽聽聽聽聽聽聽聽 var sql:String=''SELECT * FROM ''+tabla+'' ORDER BY id'';
聽聽聽聽聽聽聽聽聽聽聽 consulta.text=sql;
聽聽聽聽聽聽聽聽聽聽聽 consulta.execute();
聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽 private function onResultado(e:SQLEvent) {

聽聽聽聽聽聽聽聽聽聽聽 var result:SQLResult = e.target.getResult();
聽聽聽聽聽聽聽聽聽聽聽 ruta.dataGrid.removeAll();
聽聽聽聽聽聽聽聽聽聽聽 dp = new DataProvider();
聽聽聽聽聽聽聽聽聽聽聽 for each (var row:Object in result.data) {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 dp.addItem(row);
聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽 ruta.dataGrid.dataProvider = dp;

聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽 private function onError(e:SQLErrorEvent){
聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽 ruta.texto.text=e.error.message+'', details: ''+e.error.details
聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽 }
聽聽聽 }

}

thanks for the help

Actionscript 3 - AIR - SQLite: no such...

where's dodb assigned to true if the db exists??

Actionscript 3 - AIR - SQLite: no such...

Hi kglad, and thanks for answering

If the db exists, the variable dodb is not assigned to true, instead the scripts executes the function getData in onOpen private function.

thnx


are you sure you created a table?聽 your syntax doesn't look correct to me:聽 there shouldn't be single quotes surrounding the table name.


Hi.

you are right about the quotes, but before I tried widthout quotes, and I got the same error.


did you check to see if you've created the table?


yes, in fact, the listener conn.addEventListener(SQLEvent.OPEN, onOpen); works, it means it opens the database


that's not what i asked.


I install the air app in my own computer, and I cannot find the db in files program%26gt;my app .... do you have any example how to do it?

thnx


i think you're creating the db.聽 it's the table i don't think you're creating.

what's your operating system?


my SO is: windows xp pro

Yes, I think my problem is the table exactly... but I do not understand why that part of the script doesn't work


if you've published (but not necessary executed) your air file, check under:

Documents and Settings/username/applicationdata/

for your air directory.聽 depending on your air certificate setting the folder under application data will have any number of names but will contain your application name as part of the directory name.

for example, my certificate uses, com.kglad and my applicationstoragedirectory (if the app name is sampleApp.air) will be:

com.kglad.sampleAppxxx


I just checked and I could see the file mydb.db... that's the name I put the database in my custom class


yes, but you don't have that table.聽 you need to remove that if-statement that checks for the database because you're incorrectly assuming if the database exists, the table exists.

No comments:

Post a Comment