View Full Version : Attaching a database to your application

08-31-2008, 01:40 AM
I'm trying to attach a local pre-made database to my application and then be able to update it and such. Well, the attaching part is fairly simple, but I read that AIR makes the database a read-only file since it is with all your other files. I also read that I need to write some code that will copy that database to another location on the user's drive so that I can write to it.

Here's the site that talks about how to do it.
I tried it a couple different ways but I can't figure it out. I'm not even sure of the best location to copy it to.

Any help or suggestions would be greatly appreciated. Thanks.

08-31-2008, 10:06 PM
Well, I apparently figured it out. Here's my final code:

private function openDatabase():void {
conn = new SQLConnection();
var dbFile:File = File.applicationDirectory.resolvePath("db/Contacts.db");
var dbWorkedFile:File = File.documentsDirectory.resolvePath("Contacts.db");

conn.addEventListener(SQLEvent.OPEN, openHandler);
else {
conn.addEventListener(SQLEvent.OPEN, createHandler);
conn.addEventListener(SQLErrorEvent.ERROR, errorHandler);

Looking at this code just now I realized that I didn't use the dbWorkedFile in the conn.openAsync(). Maybe I don't really need it. Not sure if this helps but I wanted to add it in case it might be of use.