Hello,
I am wondering if I can kill two birds with one stone here. I am trying to SELECT items from an SQLite database, and I believe I am doing that successfully, even though my trace statements are returning a null.
All of the tutorials I have read, they take the items from the db and puts them into a data grid as a contact manager or something. I want to put the objects in an array and use them as a random name generator. When you get the result.data() I think it returns just an object.
So… How do I extract String information from an object and an SQL Object. Is there a function in the object class or the result class that Im missing? Here is some of my code. Thanks for the help!
import flash.data.SQLConnection;import flash.filesystem.File;
import flash.data.SQLStatement;
import flash.data.SQLResult;
var connection:SQLConnection;
var selectNames:SQLStatement;
generate.addEventListener(MouseEvent.CLICK, openConnection);
function openConnection(e:MouseEvent):void
{
var randomDb:File = File.desktopDirectory.resolvePath("classes.db");
connection = new SQLConnection;
connection.addEventListener(SQLEvent.OPEN, onOpen);
connection.addEventListener(SQLErrorEvent.ERROR, onDBError);
connection.openAsync(randomDb);
}
function onDBError(event:SQLErrorEvent):void
{
trace ("The Database Has An Error!");
}
function onOpen(event:SQLEvent):void
{
trace ("Successful");
var selectNames = new SQLStatement;
selectNames.sqlConnection = connection;
var names:String = "SELECT firstname, lastname FROM sections WHERE (teacher = 'kohn')";
selectNames.text = names;
selectNames.addEventListener(SQLEvent.RESULT, onAddComplete);
selectNames.addEventListener(SQLErrorEvent.ERROR, onDBError);
selectNames.execute();
}
function onAddComplete(event:SQLEvent):void
{
var selectNames:SQLStatement = event.target as SQLStatement;
var results:SQLResult = selectNames.getResult();
trace ("Check Values");
trace (results);
}