PDA

View Full Version : SQL Lite issue in AIR


crosswaystudios
08-08-2008, 06:08 PM
ok - I had gotten a little help from a Platform Evangelist at Adobe (Ryan Stewert) on this issue - now I can't get in touch with him... I am a noob to AIR 1.1 and Flex and I am totally confused as to why this is not working the way it should be...

Now with that outta the way - here is what I wanna do... I have several canvas contained in a viewstack. In these canvas, I have a combobox control that I want to display prepoulated data that is contained in an sqllite database. This data is in a table and in it's own column. Now my issue - I get the listing of [object binding] inside the combobox when I debug the app... The code for the SQL is of course AS3 - and is as follows:

<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import flash.events.SQLEvent
import mx.rpc.events.ResultEvent;
import flash.data.SQLResult;
import flash.data.SQLConnection;
import flash.filesystem.File;
import flash.data.SQLStatement;
import flash.data.SQLConnection;

private var conn:SQLConnection;
private var dbFile:File;
private var createStmt:SQLStatement;
private var selectStmt:SQLStatement;



private function init():void
{
var dbFile:File = File.applicationStorageDirectory.resolvePath("tagData.sqlite");

conn = new SQLConnection();
conn.addEventListener(SQLEvent.OPEN, openSuccess);
conn.addEventListener(SQLErrorEvent.ERROR, openFailure);

status = "Opening database";

conn.openAsync(dbFile);

}

private function openSuccess(event:SQLEvent):void
{
conn.removeEventListener(SQLEvent.OPEN, openSuccess);
conn.removeEventListener(SQLErrorEvent.ERROR, openFailure);


}

private function openFailure(event:SQLErrorEvent):void
{
conn.removeEventListener(SQLEvent.OPEN, openSuccess);
conn.removeEventListener(SQLErrorEvent.ERROR, openFailure);

status = "Error opening database";

trace("event.error.message:", event.error.message);
trace("event.error.details:", event.error.details);
}

private function manComboQuery (event:SQLEvent):void
{
var q:SQLStatement = new SQLStatement();
q.text = "Select ManufacturerName FROM Manufacturers"
q.sqlConnection = conn;
q.addEventListener(SQLEvent.RESULT, manQueryResult);
q.addEventListener(SQLErrorEvent.ERROR, manQueryError);
q.execute();
}

[Bindable]

private var result:ArrayCollection

private function manQueryResult (event:SQLEvent):void
{
var r:SQLResult = SQLStatement(event.currentTarget).getResult();
result = new ArrayCollection;

}

private function manQueryError (event:SQLErrorEvent):void
{
trace("BREAKER");
}

]]>
</mx:Script>
Can someone please help me with this issue...

crosswaystudios
08-08-2008, 07:40 PM
ok - I had gotten a little help from a Platform Evangelist at Adobe (Ryan Stewert) on this issue - now I can't get in touch with him... I am a noob to AIR 1.1 and Flex and I am totally confused as to why this is not working the way it should be...

Now with that outta the way - here is what I wanna do... I have several canvas contained in a viewstack. In these canvas, I have a combobox control that I want to display prepoulated data that is contained in an sqllite database. This data is in a table and in it's own column. Now my issue - I get the listing of [object binding] inside the combobox when I debug the app... The code for the SQL is of course AS3 - and is as follows:

<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import flash.events.SQLEvent
import mx.rpc.events.ResultEvent;
import flash.data.SQLResult;
import flash.data.SQLConnection;
import flash.filesystem.File;
import flash.data.SQLStatement;
import flash.data.SQLConnection;

private var conn:SQLConnection;
private var dbFile:File;
private var createStmt:SQLStatement;
private var selectStmt:SQLStatement;



private function init():void
{
var dbFile:File = File.applicationStorageDirectory.resolvePath("tagData.sqlite");

conn = new SQLConnection();
conn.addEventListener(SQLEvent.OPEN, openSuccess);
conn.addEventListener(SQLErrorEvent.ERROR, openFailure);

status = "Opening database";

conn.openAsync(dbFile);

}

private function openSuccess(event:SQLEvent):void
{
conn.removeEventListener(SQLEvent.OPEN, openSuccess);
conn.removeEventListener(SQLErrorEvent.ERROR, openFailure);


}

private function openFailure(event:SQLErrorEvent):void
{
conn.removeEventListener(SQLEvent.OPEN, openSuccess);
conn.removeEventListener(SQLErrorEvent.ERROR, openFailure);

status = "Error opening database";

trace("event.error.message:", event.error.message);
trace("event.error.details:", event.error.details);
}

private function manComboQuery (event:SQLEvent):void
{
var q:SQLStatement = new SQLStatement();
q.text = "Select ManufacturerName FROM Manufacturers"
q.sqlConnection = conn;
q.addEventListener(SQLEvent.RESULT, manQueryResult);
q.addEventListener(SQLErrorEvent.ERROR, manQueryError);
q.execute();
}

[Bindable]

private var result:ArrayCollection

private function manQueryResult (event:SQLEvent):void
{
var r:SQLResult = SQLStatement(event.currentTarget).getResult();
result = new ArrayCollection;

}

private function manQueryError (event:SQLErrorEvent):void
{
trace("BREAKER");
}



]]>
</mx:Script>

Can someone please help!?!?!

evride
08-09-2008, 01:38 PM
small problem. capitalize all letters of the SELECT sql command.


q.text = "SELECT ManufacturerName FROM Manufacturers";

that goes for INSERT INTO, DELETE FROM, UPDATE and other sql thingymajigers.

crosswaystudios
08-12-2008, 01:47 AM
ok got it working now - how to duplicate it... I need to do this same call from the same database calling from different tables and columns - how to do this is AS3 - I don't know - HELP!!!!

crosswaystudios
08-12-2008, 01:48 AM
<CODE><mx:Script>
<![CDATA[
import flash.events.SQLEvent;
import mx.rpc.events.ResultEvent;
import flash.data.SQLResult;
import flash.data.SQLConnection;
import flash.filesystem.File;
import flash.data.SQLStatement;
import flash.data.SQLConnection;

private var conn:SQLConnection;
private var dbFile:File;
private var createStmt:SQLStatement;
private var selectStmt:SQLStatement;



private function init():void
{
var dbFile:File = File.applicationDirectory.resolvePath("tagData.sqlite");

conn = new SQLConnection();
conn.addEventListener(SQLEvent.OPEN, openSuccess);
conn.addEventListener(SQLErrorEvent.ERROR, openFailure);

status = "Opening database";

conn.openAsync(dbFile);

}

private function openSuccess(event:SQLEvent):void

{
conn.removeEventListener(SQLEvent.OPEN, openSuccess);
conn.removeEventListener(SQLErrorEvent.ERROR, openFailure);
manComboQuery();

}

private function openFailure(event:SQLErrorEvent):void
{
conn.removeEventListener(SQLEvent.OPEN, openSuccess);
conn.removeEventListener(SQLErrorEvent.ERROR, openFailure);

status = "Error opening database";

trace("event.error.message:", event.error.message);
trace("event.error.details:", event.error.details);
}

private function manComboQuery ():void
{
var q:SQLStatement = new SQLStatement();
q.text = "SELECT ManufacturerName FROM Manufacturers"
q.sqlConnection = conn;
q.addEventListener(SQLEvent.RESULT, manQueryResult);
q.addEventListener(SQLErrorEvent.ERROR, manQueryError);
q.execute();
}

[Bindable]
private var manarrResult:Array = new Array();

private function manQueryResult (event:SQLEvent):void
{
var r:SQLResult = SQLStatement(event.currentTarget).getResult();
manarrResult = r.data
trace ("test")
}

private function manQueryError (event:SQLErrorEvent):void
{
trace("BREAKER");
}
]]>
</mx:Script></CODE>