You want to include an existing SQLite database with an Adobe AIR application.
Embed an existing SQLite database in the AIR application and copy it to another folder to interact with it.
Many desktop applications use databases to store data locally on the user's computer. In some AIR applications, you need to embed an existing SQLite database within the packaged
.air file.
The
.air file is a package with some files inside. When you install an AIR application on your computer, you copy those files into the application folder or a subfolder. Any files you want to include in an AIR application must be packaged with it when you 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 you try to work with a database file in this directory, it will fail with a silent error. To make this work, you 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. You can then work with your 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:
var dbFile:File = File.applicationDirectory.resolvePath("db/software.db");
var dbWorkFile:File = File.documentsDirectory.resolvePath("software.db");
if(!dbWorkFile.exists){
dbFile.copyTo(dbWorkedFile);
}
This recipe was originally contributed by Marco Casario as part of O'Reilly's Flex 4 Cookbook.
+