SQLite Databases
Just as within Adobe AIR on the desktop, you can utilize an SQLite database for storing data on a mobile device. The example below will create a database, use a simple form to save data to that database, and retrieve and display the stored data.
Let’s review the code below. At the top you will see the database
file defined as a file called users.db within the
userDirectory
. Next, the
SQLConnection
is defined. Finally, there are several
SQLStatement
s declared and SQL strings defined, which
will be used for working with the database.
Within the applicationComplete
event handler, the
SQLConnection
is initiated and two event listeners are
added to listen for SQLEvent.OPEN
and
SQLErrorEvent.ERROR
. Finally, the
openAsync
method is called and the
db file is passed in.
After the database is opened, the openHandler
function is called. Within this function, the SQLEvent.OPEN
event listener is removed. Next,
the createTableStmt
is created, configured, and
executed. This statement will create a new table called
Users if it doesn’t yet exist. If this statement is
successful, then the createResult
method is called.
Within the createResult
method, the SQLEvent.RESULT
event is removed and the
selectUsers
method is called.
Within the selectUsers
method, the
selectStmt
is created, configured, and executed. This
statement will return all rows within the Users table. This data is then
stored within the selectStmt
. If this statement is
successful, then the selectResult
method is called. ...
Get Developing iOS Applications with Flex 4.5 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.