Appcelerator Blog

The Leading Resource for All Things Mobile

How to create and install a pre-populated database

0 Flares 0 Flares ×
Editor’s note: This blog post is a basic tutorial. The most up-to-date version is available in the wiki. Using the Titanium.Database.install method allows you to install a database that is pre-populated and packaged with the application in the resources directory. When the Titanium.Database.install method is called, it will install that database, or if the database is already installed, it will simply open the database. This will allow you to create a new database, run SQL against it, and end up with a pre-populated database.
  • Place the resulting file in your resources folder and you will be able to use it with the install function:
var db = Titanium.Database.install('testdb.db','myDB');
This will install the testdb.db database as myDB.sql in the databases directory which is available using:
Ti.Filesystem.applicationSupportDirectory+'/database'.
From there you can now open that database using Ti.Database.open(‘myDB’); Always remember to close your database and result set when you are done accessing them.
0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×

Sign up for updates!

Become a mobile leader. Take the first step to scale mobile innovation throughout your enterprise.
Get in touch
computer and tablet showing Appcelerator software
Start free, grow from there.
0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×