I am trying to develop an AIR application with the following structure in Flex Builder,
where I have a pre-build a database containing several tables.
//Some classes here
I try to access the sample.db with the code of File.applicationStorageDirectory.resolvePath("./db/sample.db") ,but this code doesn't work because the file can not be found when I run the application with Flex Builder.
So, I changed the code to File.applicationStorageDirectory.resolvePath("sample.db") as the Adobe document shows, and I could connect to the database as expected.
However, with the new code, I found that the sample.db was not the pre-build one
because I got TABLE NOT FOUND error when trying to access some pre-build tables.
The sample.db file was not in bin-debug folder, but in User\AppData\Roaming\ProjectName\LocalStore
where I only found the database file itself.
Is there any way to publish the pre-build database with AIR so that I don't need to write sql statement
to create tables at runtime?
Yes. Include a "template" database file in the application package. Before you open the database, check whether the database file exists in the application storage directory. If the file does not exist, copy the template database to the storage directory. Then open the database.