Include a DB in an AIR Application
Today, when I was reading my new Flex 4 cookbook, I saw the little, nice and almost old tip in there that will talk about that here, just as same as the book. The problem is including a database in an AIR application… We want to include an existing SQLite database with an Adobe AIR application. We can embed an existing SQLite database in our AIR application and copy it to another folder to interact with.
Many desktop applications use databases to store data locally on the user’s computer. In some AIR applications, we need to embed an existing SQLite database within the packaged .air file. As you know, the .air file is a package with some files inside. When we install an AIR application on our computer, we copy those files into the application folder or a subfolder. Any files we want to include in an AIR application must be packaged with it when we create it. This applies to images, text files, and database files, including an existing SQLite database created for another application or with another program. Note that the application folder, File.applicationDirectory, is read-only. If we try to work with a database file in this directory, it will fail with a silent error. To make this work, we must copy the database file into another folder, such as the Documents folder or the desktop folder, using the copyTo() method of the File class. we can then work with our database and create new records, update records, or delete them.
In this ActionScript example, the file software.db is copied from the application directory of the AIR application to the Documents directory of the user’s computer. After the file is copied, you can then interact with it as needed: (persian version – مشاهده مقاله، به زبان فارسی)
var dbFile:File = File.applicationDirectory.resolvePath("db/software.db");
var dbWorkFile:File = File.documentsDirectory.resolvePath("software.db");
if(!dbWorkFile.exists){
dbFile.copyTo(dbWorkedFile);
}
Tags: Adobe, AIR, Flash Builder 4, Flex 4, SQLite
Trackback from your site.