Copy link to clipboard
Copied
I'm making a quiz game for android and iOS using flash.
I want to connect to a pre-populated database with the questions in.
I've found a lot of tutorials that explain how to create a database and then query the results, just nothing really useful on working with a prepopulated dB.
Any help would be super!
Copy link to clipboard
Copied
To use a pre-populated database, you just have included the database file when you package your app. Go to AIR for Android Settings, and use the Included files controls.
Note, that the database will be in a READ-ONLY directory on the device. You will need to copy the database to the documents directory in order to write to it.
Chris
Copy link to clipboard
Copied
Chris,
Thanks for the reply.
Ah, I see! Didn't know this, thanks.
That's added, so how do I now connect and read from the database?
I googled before asking, and tried a some code I found online but had no luck. When I traced an SQL statement I recieved 'null'. I can get it to work when the database is created within AS3, with insert statements, etc. Just not with an existing database. Very fustrating, but surely I'm close?
Thanks again,
Charles
Copy link to clipboard
Copied
This should be straightforward; you follow the examples for SQLConnection and SQLStatement. You want something like:
var dbFile : File = File.applicationDirectory.resolvePath(dbName);
var sqlConnection : SQLConnection = new SQLConnection();
sqlConnection.open(dbFile, SQLMode.READ);
var query : SQLStatement = new SQLStatement();
query.sqlConnection = sqlConnection;
query.text = "SELECT * FROM table WHERE name LIKE :name AND service = :service;"
query.parameters[":name"] = name;
query.parameters[":service"] = service;
query.execute();
var result : SQLResult = query.getResult();
Copy link to clipboard
Copied
Thanks,
It's taken me a couple of hours but it's worked!
Seems pretty simple now, always the way.
Now, I have it displaying in a dataGrid but can't put it in an array. Any idea why?
var result : SQLResult = query.getResult();
var info:Array = result.data;
resultsGrid.dataProvider = new DataProvider(info);
var firstname:String = info.toString();
trace(firstname);
I finally have SQL working, oh the possibilities!