Skip to main content
CharlesBannister
Participant
Feb 20, 2013 9:59 PM UTC
Question

Flash. SQLite, pre-populated. Help.

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!

This topic is closed to new replies. Start a new post to keep the conversation going.

4 replies

Chris W. Griffith
Community Expert
Community Expert
Feb 20, 2013 11:48 PM UTC

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

Translate
CharlesBannister
Participant
Feb 21, 2013 12:09 PM UTC

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

Translate
Inspiring
Feb 21, 2013 7:25 PM UTC

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();

Translate