11.3. Working with Data

Now that we have created a new database and added a new table to the database, we can start to add, retrieve, update, and delete data. The following section demonstrates how to do all of these using the SQLStatement class. Each of these operations is done by creating functions in the same manner as the createTable() function.

11.3.1. Saving Data

Saving data to our new table is a relatively painless process. Before we can work on the SQLStatement to do the data insert, we need to create some TextInput components to hold the data that need to be inserted. Add the block of code from Listing 11-4 to the bottom of the Chapter11_SQLite.mxml file.

Example 11-4. The MXML code needed for the TextInput components
<mx:HBox>
  <mx:Label text="Username:"/>
  <mx:TextInput id="usernameTxt" width="100" text="rich"/>
  <mx:Label text="Password:"/>
  <mx:TextInput id="passwordTxt" displayAsPassword="true" width="100"
                text="password"/>
  <mx:Button label="Insert User" click="insertRecord()"/>
</mx:HBox<
<mx:HRule width="100%"/>

Notice, in the <mx:Button> component, the click property calls an insertRecord() function that has yet to be created. Before creating this function, we need to add a SQLStatement to the file named insertStatement. Add this new var to the Chapter11_SQLite.mxml in the same way you did with the createTableStatement var.

private var insertStatement:SQLStatement;

Now, we can create the new function named insertRecord(), which will actually do the work of inserting ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.