• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Flash. SQLite, pre-populated. Help.

Participant ,
Feb 20, 2013 Feb 20, 2013

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!

TOPICS
Development

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 20, 2013 Feb 20, 2013

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 21, 2013 Feb 21, 2013

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 21, 2013 Feb 21, 2013

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 21, 2013 Feb 21, 2013

Copy link to clipboard

Copied

LATEST

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines