SQLite Databases

Description

When you create a Cordova project, you can include pre-populated SQLite database files as part of the Cordova project.

A genie allows you to create the SQLite databases that you include with your Cordova project. Watch the video below to learn more:

If your Cordova project includes pre-populated SQLite databases, your UX component can work with the data in these SQLite databases using Action Javascript. See PhoneGap - SQLite Actions for more information.

If you are including pre-populated SQLite databases in your project, be sure to specify the following plugins: Device, File, File Transfer, SQLitePluginExt.

To define the SQLite databases that should be part of your Cordova project, click the smart field for the SQLite Databases property in the Cordova Genie.

images/phonegapbuilder_sqlite.jpg

This will open a dialog where you can define your SQLite databases.

Your project can include multiple SQLite databases and each database can include multiple tables. Each SQLite database is contained in a single file and this file is automatically added to the Additional Files Required setting in the builder.

You can choose to put all of the tables you want in your SQLite databases in a single SQLite database, or you can use multiple SQLite databases - the choice is yours.

images/phonegap_sqlite2.jpg

Once you add a new SQLite database to the above dialog, you can click the Define SQLite Database Contents button to specify the tables that should be in the SQLite database. For each table that you specify you can define how the table should be populated. The options are to perform a SQL query to extract data from any SQL database supported by AlphaDAO, static data, or Xbasic. If you choose the Xbasic option, you can specify Xbasic code that will return data that are used to populate a table.

Once you have defined the SQLite databases, click the Create SQLite Database Files button to actually create the SQLite database files. These files will be created in the www folder in your Cordova project.

Contrast creating pre-populated SQLite databases with making an Ajax callback to the server and dynamically creating the SQLite database. Dynamically creating SQLite databases is a built-in action in Action Javascript. See PhoneGap - SQLite Actions.