Skip to main content
CharlesBannister
Participant
February 20, 2013
Question

Flash. SQLite, pre-populated. Help.

  • February 20, 2013
  • 4 replies
  • 1383 views

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 has been closed for replies.

4 replies

Chris W. Griffith
Community Expert
Community Expert
February 20, 2013

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

CharlesBannister
Participant
February 21, 2013

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

Inspiring
February 21, 2013

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