SQLite Databases
Just as with Adobe AIR on the desktop, you can use an SQLite database to store 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; two event listeners are
added to listen for SQLEvent.OPEN
and
SQLErrorEvent.ERROR
; and 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,
createTableStmt
is created, configured, and executed.
This statement will create a new table called Users (if it doesn’t yet
exist). If it is successful, then the
createResult
method is called. Within the
create
Result
method, the SQLEvent.RESULT
event is removed and the
selectUsers
method is called.
Within the selectUsers
method,
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 it is successful, the
selectResult
method is called. Within the select
Result
method, the data ...
Get Developing Android 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.