11.2. Getting Started

Before we can do any examples working with SQLite, we need to create a new SQLite database. The following section will demonstrate how to create such a SQLite database, create a table, insert data, read data, and delete data. For the examples in this chapter, please create a new AIR project named Chapter11_SQLite, and copy the contents of Listing 11-1 into Chapter11_SQLite.mxml. We will build on this file as we explore the features of SQLite throughout this chapter. At the end of each section, there will be a listing that shows the current version of the Chapter11_SQLite.mxml file.

11.2.1. Creating a SQLite Database

Creating a SQLite database is the same as creating a file. If you remember back in Chapter 8, we used a piece of code like this to create a file:

var newFile:File = File.desktopDirectory.resolvePath("MyNewFile.txt");

Creating a SQLite database is exactly the same except that the file extension will be .db. Before you can open the database, you will have to create a SQLConnection using the flash.data.SQLConnection class to do so.

To get started, let's take a look at the example in Listing 11-1 to see what is required to create a connection to a SQLite database. The first thing needed is imports of the needed SQL and File classes. Next a SQLConnection variable is set up as a class variable to allow for access by additional functions to come later in this chapter. Looking at the openDatabase function, you will notice that the SQLConnection class ...

Get Beginning Adobe® AIR™: Building Applications for the Adobe Integrated Runtime now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.