SlideShare a Scribd company logo
Introduction to SQLite
in Adobe AIR
Peter Elst - Flash Platform Consultant
Why SQLite in Adobe AIR?
■ Embedded SQL Database Engine

■ Implements most of SQL92

■ Light-weight, cross-platform, open source

■ No setup, configuration or server required

■ Each database is contained within a single file
How do you use it?
1. Create a File reference

2. Create an instance of flash.data.SQLConnection and
   flash.data.SQLStatement

3. Open the database connection

4. Specify the connection and SQL query to run

5. Run SQLStatement.execute()
How do you use it?
 import flash.filesystem.File;
 import flash.data.*;

 var dbFile:File =
 File.applicationStorageDirectory.resolvePath("contacts.db");

 var sqlConn:SQLConnection = new SQLConnection();
 var sqlStatement:SQLStatement = new SQLStatement();

 sqlConn.open(dbFile);

 sqlStatement.sqlConnection = sqlConn;
 sqlStatement.text = "SELECT * FROM contacts";
 sqlStatement.execute();

 var result:Array = sqlStatement.getResult().data;
Synchronous versus Asynchronous
■ Synchronous - blocks application until result is available

   var sqlConn:SQLConnection = new SQLConnection();
   sqlConn.open(dbFile);

   var result:SQLResult = sqlConn.getResult().result;


■ Asynchronous - uses events and event listeners

   var sqlConn:SQLConnection = new SQLConnection();

   sqlConn.addEventListener(SQLResultEvent.RESULT, onSQLResult);
   sqlConn.addEventListener(SQLResultEvent.ERROR, onSQLError);

   sqlConn.openAsync(dbFile);
flash.data.SQLConnection
■ Connects to the database file

■ Provides events for asynchronous use

■ Schema access
flash.data.SQLStatement
■ Executes a SQL query on the specified database connection

■ Provides events for asynchronous use

■ Supports result paging
flash.data.SQLMode
■ SQLMode.CREATE (default)

  ■ open connection and create database if it doesn’t exist

■ SQLMode.READ

  ■ open connection as read only

■ SQLMode.UPDATE

  ■ open connection, don’t create database if it doesn’t exist
Storage types
■ NULL - NULL value (null)

■ INTEGER - signed integer (int)

■ REAL - floating point (Number)

■ TEXT - UTF16 text string (String)

■ BLOB - blob of data (ByteArray)
AIR specific column affinities
■ String - String value (equivalent to TEXT)

■ Number - floating point number (equivalent to REAL)

■ Boolean - Boolean class

■ Date - Date class

■ XML - XML class

■ XMLList - XMLList class

■ Object - Object class
SQLStatement Parameters
■ The parameters feature protects your SQL statements from
  SQL injection

  var sqlStatement:SQLStatement = new SQLStatement();
  sqlStatement.sqlConnection = sqlConn;
  sqlStatement.text = "SELECT * FROM contacts WHERE id = @ID";
  sqlStatement.parameters["@ID"] = someVariable;
  sqlStatement.execute();


■ You can use the @ or : symbol to denote a parameter to be
  replaced, works both string based as index based

  sqlStatement.parameters[0] = someVariable;
Result Paging
■ Paging allows you to limit the amount of rows you get
  returned when doing a select operation

  var sqlStatement:SQLStatement = new SQLStatement();
  sqlStatement.sqlConnection = sqlConn;
  sqlStatement.text = "SELECT * FROM contacts";
  sqlStatement.execute(10);


■ You can get the next batch of rows returned by calling the
  next method on the SQLStatement instance

  sqlStatement.next();
flash.data.SQLResult
■ SQLResult.data - array of objects for each row of the result

■ SQLResult.complete - returns a boolean indicating whether
  or not the full result was shown

■ SQLResult.lastInsertRowID - return id for the last row that
  was inserted

■ SQLResult.rowsAffected - number of rows affected by an
  insert, update or delete operation
Transactions
■ Transactions allow multiple SQL statements to run within one
  write operation to the database

■ Much more optimized way of handling large insert operations,
  allows rollback of the complete transaction if an error occurs

 var sqlStatement:SQLStatement = new SQLStatement();
 sqlStatement.sqlConnection = sqlConn;
 sqlStatement.text = "INSERT into contacts VALUES (@NAME, @EMAIL)";

 sqlConn.begin();
 for(var i:uint=0; i<contacts.length; i++) {
   sqlStatement.parameters["@NAME"] = contacts[i].name;
   sqlStatement.parameters["@EMAIL"] = contacts[i].email;
   sqlStatement.execute();
 }
 sqlConn.commit();
Database Schema
■ Allows you to introspect tables, views, columns, indices, triggers

 var sqlConn:SQLConnection = new SQLConnection();
 sqlConn.open(dbFile);

 sqlConn.loadSchema();
 var result:SQLSchemaResult = sqlConn.getSchemaResult();

 var table:SQLTableSchema = result.tables[0];
 var column:SQLColumnSchema = table.columns[0];

 trace(column.name);
 // returns name of the first column in the first table
Schema demo
Database encryption
■ New feature in AIR 1.5
■ Password protect database files

 var encryptionKey:ByteArray = new ByteArray();
 encryptionKey.writeUTFBytes("notverysecretpassword");

 var sqlConn:SQLConnection = new SQLConnection();
 sqlConn.open(dbFile,SQLMode.READ,null,false,1024,encryptionKey);
Encryption best practices
■ Do not embed passwords in your application!

■ com.adobe.air.crypto.EncryptionKeyGenerator
      ■ Secure solution: creates random salt and stores in the
        EncryptedLocalStore (linked to user and machine)
      ■ Prevents dictionary attack

■ com.dehats.air.sqlite.SimpleEncryptionKeyGenerator
      ■ Less secure but allows access by other users and other
        applications, doesn’t generate a random salt value.

         http://bit.ly/SimpleEncryptionKeyGenerator
Database synchronization
■ Synchronize database between server and client(s)
■ Some different strategies
     ■ overwrite (server overwrites client)
     ■ check what to synchronize
       ■ timestamp field
       ■ field by field comparison
       ■ dirty flag

■ LiveCycle Data Services has built-in SQLite synchronization
  support including offline caching and conflict management.
SQLite Tools
Mac OSX Terminal
Lita - SQLite database administration
DAO-Ext - value object generator
What is DAO?
■ Data Access Objects - abstract interface to a database
     ■ implements common features (select, update, delete, ...)
     ■ Uses value objects (VO)
What is DAO?
■ Data Access Objects - abstract interface to a database
     ■ implements common features (select, update, delete, ...)
     ■ Uses value objects (VO)


■ Value Objects (also known as Data Transfer Objects)
     ■ don’t implement any behavior
     ■ encapsulates properties through getter/setter methods
     ■ represent an entry in a database table
Example VO
 public class contactsVO {

     private var _name:String;

     public function get name():String {
         return _name;
     }

     public function set name(value:String):void   {
         _name = value;
     }

     ...

 }
Example DAO
 public class contactsDAO {

     public function insertRow(rowItem:contactsVO):void {
         ...
     }

     public function updateRow(rowItem:contactsVO):void {
         ...
     }
     public function deleteRow(rowItem:contactsVO):void {
       ...
     }

 }
DAO demo
SQLite wrapper classes
■ Simple way to use SQLite features in your application
■ ActionScript 3.0 classes, primarily for use as tags in MXML


<sql:SQLite id="myDB" file="contacts.db" open="myQuery.execute()" />

<sql:Query id="myQuery" connection="{myDB.connection}"
           sql="SELECT * FROM contacts" />


<mx:DataGrid id="myDataGrid" dataProvider="{myQuery.data}" />
<mx:Button label="Refresh data" click="myQuery.execute()" />
SQLite wrapper - SQLite class
■ Properties
    ■ file - name of database file
    ■ connection - returns SQLConnection instance

■ Methods
   ■ open - create database connection
   ■ close - close database connection

■ Events
    ■ open - database connection is opened
    ■ close - database connection is closed
    ■ error - error connecting to database
SQLite wrapper - Query class
■ Properties
    ■ connection - reference to SQLConnection
    ■ sql - String value of SQL statement
    ■ parameters - parameters for SQL statement
    ■ data - result returned from query

■ Methods
   ■ execute - run query on database

■ Events
    ■ result - result received from query
    ■ error - error executing query
SQLite wrapper demo
Resources
■ Lita - SQLite Administration Tool by David Deraedt
  www.dehats.com/drupal/?q=node/58

■ DAO-Ext by Comtaste
  code.google.com/p/dao-ext/

■ Adobe AIR Developer Center
  www.adobe.com/devnet/air/

■ Adobe AIR Marketplace
  www.adobe.com/go/airmarketplace
Thanks for your time
 Any questions or feedback - feel free to get in touch!


    blog       www.peterelst.com
    email      info@peterelst.com
    twitter    @peterelst




                                         e confe rence!
                         rest o     f th
              En joy the

More Related Content

What's hot (20)

PDF
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
Dave Stokes
 
PDF
Longhorn PHP - MySQL Indexes, Histograms, Locking Options, and Other Ways to ...
Dave Stokes
 
PPTX
Oracle basic queries
PRAKHAR JHA
 
PPTX
Preethi apex-basics-jan19
Preethi Harris
 
PPTX
Oraclesql
Priya Goyal
 
PDF
Data Love Conference - Window Functions for Database Analytics
Dave Stokes
 
PDF
Open Source World June '21 -- JSON Within a Relational Database
Dave Stokes
 
DOCX
Accessing data with android cursors
info_zybotech
 
PPTX
cPanel now supports MySQL 8.0 - My Top Seven Features
Dave Stokes
 
PPTX
Difference Between Sql - MySql and Oracle
Steve Johnson
 
PPTX
Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...
Dave Stokes
 
PDF
Ado.Net
LiquidHub
 
PPT
MYSQL
Ankush Jain
 
PPTX
Confoo 2021 - MySQL Indexes & Histograms
Dave Stokes
 
PDF
SQLite in Adobe AIR
Peter Elst
 
PPT
Xml parsers
Manav Prasad
 
PDF
How to execute an oracle stored procedure with nested table as a parameter fr...
Priyobroto Ghosh (Mule ESB Certified)
 
PPTX
Ch06 ado.net fundamentals
Madhuri Kavade
 
PDF
Dutch PHP Conference 2021 - MySQL Indexes and Histograms
Dave Stokes
 
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
Dave Stokes
 
Longhorn PHP - MySQL Indexes, Histograms, Locking Options, and Other Ways to ...
Dave Stokes
 
Oracle basic queries
PRAKHAR JHA
 
Preethi apex-basics-jan19
Preethi Harris
 
Oraclesql
Priya Goyal
 
Data Love Conference - Window Functions for Database Analytics
Dave Stokes
 
Open Source World June '21 -- JSON Within a Relational Database
Dave Stokes
 
Accessing data with android cursors
info_zybotech
 
cPanel now supports MySQL 8.0 - My Top Seven Features
Dave Stokes
 
Difference Between Sql - MySql and Oracle
Steve Johnson
 
Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...
Dave Stokes
 
Ado.Net
LiquidHub
 
Confoo 2021 - MySQL Indexes & Histograms
Dave Stokes
 
SQLite in Adobe AIR
Peter Elst
 
Xml parsers
Manav Prasad
 
How to execute an oracle stored procedure with nested table as a parameter fr...
Priyobroto Ghosh (Mule ESB Certified)
 
Ch06 ado.net fundamentals
Madhuri Kavade
 
Dutch PHP Conference 2021 - MySQL Indexes and Histograms
Dave Stokes
 

Similar to Introduction to SQLite in Adobe AIR (20)

ZIP
Introduction to SQLite in Adobe AIR 1.5
Peter Elst
 
PPT
Sqllite
Senthil Kumar
 
PDF
Introduction to SQLite in Adobe AIR
Peter Elst
 
PDF
Sync It Up
svoisen
 
KEY
Flash And The City 2010
Steven Peeters
 
PPTX
Data Handning with Sqlite for Android
Jakir Hossain
 
KEY
Scotch On The Rocks 2011
Steven Peeters
 
PPT
For Beginers - ADO.Net
Snehal Harawande
 
KEY
SOTR 2012
Steven Peeters
 
PPT
Marmagna desai
jmsthakur
 
PPT
ASP.NET Session 11 12
Sisir Ghosh
 
PPTX
Client storage
Parashuram N
 
PDF
Jdbc 1
Tuan Ngo
 
PPTX
Tk2323 lecture 7 sql
MengChun Lam
 
PPTX
Ado .net
Manish Singh
 
PPSX
ADO.NET
Farzad Wadia
 
PDF
NoSQL and JavaScript: a Love Story
Alexandre Morgaut
 
PDF
Jdbc[1]
Fulvio Corno
 
PDF
JDBC programming
Fulvio Corno
 
PDF
Overview Of JDBC
Mindfire Solutions
 
Introduction to SQLite in Adobe AIR 1.5
Peter Elst
 
Sqllite
Senthil Kumar
 
Introduction to SQLite in Adobe AIR
Peter Elst
 
Sync It Up
svoisen
 
Flash And The City 2010
Steven Peeters
 
Data Handning with Sqlite for Android
Jakir Hossain
 
Scotch On The Rocks 2011
Steven Peeters
 
For Beginers - ADO.Net
Snehal Harawande
 
SOTR 2012
Steven Peeters
 
Marmagna desai
jmsthakur
 
ASP.NET Session 11 12
Sisir Ghosh
 
Client storage
Parashuram N
 
Jdbc 1
Tuan Ngo
 
Tk2323 lecture 7 sql
MengChun Lam
 
Ado .net
Manish Singh
 
ADO.NET
Farzad Wadia
 
NoSQL and JavaScript: a Love Story
Alexandre Morgaut
 
Jdbc[1]
Fulvio Corno
 
JDBC programming
Fulvio Corno
 
Overview Of JDBC
Mindfire Solutions
 
Ad

More from Peter Elst (15)

KEY
P2P on the local network
Peter Elst
 
PPTX
P2P with Flash Player 10.1
Peter Elst
 
PPTX
Big boys and their litl toys
Peter Elst
 
PPTX
Yes, you can do that with AIR 2.0
Peter Elst
 
PPTX
FATC - AIR 2.0 workshop
Peter Elst
 
PPTX
Developing with Adobe AIR
Peter Elst
 
PDF
Introduction to AS3Signals
Peter Elst
 
PDF
The Secret Life of a Flash Freelancer
Peter Elst
 
PDF
Getting Creative with Adobe AIR
Peter Elst
 
PDF
Creative Programming in ActionScript 3.0
Peter Elst
 
PDF
RIA meets Desktop
Peter Elst
 
PDF
Object-Oriented ActionScript 3.0
Peter Elst
 
PDF
The Evolution of the Flash Platform
Peter Elst
 
PDF
RIA meets Desktop
Peter Elst
 
PPT
SkillsMatter - In-the-Brain session - What's new in ActionScript 3.0
Peter Elst
 
P2P on the local network
Peter Elst
 
P2P with Flash Player 10.1
Peter Elst
 
Big boys and their litl toys
Peter Elst
 
Yes, you can do that with AIR 2.0
Peter Elst
 
FATC - AIR 2.0 workshop
Peter Elst
 
Developing with Adobe AIR
Peter Elst
 
Introduction to AS3Signals
Peter Elst
 
The Secret Life of a Flash Freelancer
Peter Elst
 
Getting Creative with Adobe AIR
Peter Elst
 
Creative Programming in ActionScript 3.0
Peter Elst
 
RIA meets Desktop
Peter Elst
 
Object-Oriented ActionScript 3.0
Peter Elst
 
The Evolution of the Flash Platform
Peter Elst
 
RIA meets Desktop
Peter Elst
 
SkillsMatter - In-the-Brain session - What's new in ActionScript 3.0
Peter Elst
 
Ad

Recently uploaded (20)

PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
2025-07-15 EMEA Volledig Inzicht Dutch Webinar
ThousandEyes
 
PPTX
UI5Con 2025 - Get to Know Your UI5 Tooling
Wouter Lemaire
 
PDF
Productivity Management Software | Workstatus
Lovely Baghel
 
PDF
Apache CloudStack 201: Let's Design & Build an IaaS Cloud
ShapeBlue
 
PDF
Sustainable and comertially viable mining process.pdf
Avijit Kumar Roy
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
Arcee AI - building and working with small language models (06/25)
Julien SIMON
 
PDF
Are there government-backed agri-software initiatives in Limerick.pdf
giselawagner2
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PPTX
Machine Learning Benefits Across Industries
SynapseIndia
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PPTX
Simplifying End-to-End Apache CloudStack Deployment with a Web-Based Automati...
ShapeBlue
 
PDF
Rethinking Security Operations - Modern SOC.pdf
Haris Chughtai
 
PDF
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
PDF
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
PDF
Novus-Safe Pro: Brochure-What is Novus Safe Pro?.pdf
Novus Hi-Tech
 
PDF
UiPath vs Other Automation Tools Meeting Presentation.pdf
Tracy Dixon
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
2025-07-15 EMEA Volledig Inzicht Dutch Webinar
ThousandEyes
 
UI5Con 2025 - Get to Know Your UI5 Tooling
Wouter Lemaire
 
Productivity Management Software | Workstatus
Lovely Baghel
 
Apache CloudStack 201: Let's Design & Build an IaaS Cloud
ShapeBlue
 
Sustainable and comertially viable mining process.pdf
Avijit Kumar Roy
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Arcee AI - building and working with small language models (06/25)
Julien SIMON
 
Are there government-backed agri-software initiatives in Limerick.pdf
giselawagner2
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
Machine Learning Benefits Across Industries
SynapseIndia
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
Simplifying End-to-End Apache CloudStack Deployment with a Web-Based Automati...
ShapeBlue
 
Rethinking Security Operations - Modern SOC.pdf
Haris Chughtai
 
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
Novus-Safe Pro: Brochure-What is Novus Safe Pro?.pdf
Novus Hi-Tech
 
UiPath vs Other Automation Tools Meeting Presentation.pdf
Tracy Dixon
 

Introduction to SQLite in Adobe AIR

  • 1. Introduction to SQLite in Adobe AIR Peter Elst - Flash Platform Consultant
  • 2. Why SQLite in Adobe AIR? ■ Embedded SQL Database Engine ■ Implements most of SQL92 ■ Light-weight, cross-platform, open source ■ No setup, configuration or server required ■ Each database is contained within a single file
  • 3. How do you use it? 1. Create a File reference 2. Create an instance of flash.data.SQLConnection and flash.data.SQLStatement 3. Open the database connection 4. Specify the connection and SQL query to run 5. Run SQLStatement.execute()
  • 4. How do you use it? import flash.filesystem.File; import flash.data.*; var dbFile:File = File.applicationStorageDirectory.resolvePath("contacts.db"); var sqlConn:SQLConnection = new SQLConnection(); var sqlStatement:SQLStatement = new SQLStatement(); sqlConn.open(dbFile); sqlStatement.sqlConnection = sqlConn; sqlStatement.text = "SELECT * FROM contacts"; sqlStatement.execute(); var result:Array = sqlStatement.getResult().data;
  • 5. Synchronous versus Asynchronous ■ Synchronous - blocks application until result is available var sqlConn:SQLConnection = new SQLConnection(); sqlConn.open(dbFile); var result:SQLResult = sqlConn.getResult().result; ■ Asynchronous - uses events and event listeners var sqlConn:SQLConnection = new SQLConnection(); sqlConn.addEventListener(SQLResultEvent.RESULT, onSQLResult); sqlConn.addEventListener(SQLResultEvent.ERROR, onSQLError); sqlConn.openAsync(dbFile);
  • 6. flash.data.SQLConnection ■ Connects to the database file ■ Provides events for asynchronous use ■ Schema access
  • 7. flash.data.SQLStatement ■ Executes a SQL query on the specified database connection ■ Provides events for asynchronous use ■ Supports result paging
  • 8. flash.data.SQLMode ■ SQLMode.CREATE (default) ■ open connection and create database if it doesn’t exist ■ SQLMode.READ ■ open connection as read only ■ SQLMode.UPDATE ■ open connection, don’t create database if it doesn’t exist
  • 9. Storage types ■ NULL - NULL value (null) ■ INTEGER - signed integer (int) ■ REAL - floating point (Number) ■ TEXT - UTF16 text string (String) ■ BLOB - blob of data (ByteArray)
  • 10. AIR specific column affinities ■ String - String value (equivalent to TEXT) ■ Number - floating point number (equivalent to REAL) ■ Boolean - Boolean class ■ Date - Date class ■ XML - XML class ■ XMLList - XMLList class ■ Object - Object class
  • 11. SQLStatement Parameters ■ The parameters feature protects your SQL statements from SQL injection var sqlStatement:SQLStatement = new SQLStatement(); sqlStatement.sqlConnection = sqlConn; sqlStatement.text = "SELECT * FROM contacts WHERE id = @ID"; sqlStatement.parameters["@ID"] = someVariable; sqlStatement.execute(); ■ You can use the @ or : symbol to denote a parameter to be replaced, works both string based as index based sqlStatement.parameters[0] = someVariable;
  • 12. Result Paging ■ Paging allows you to limit the amount of rows you get returned when doing a select operation var sqlStatement:SQLStatement = new SQLStatement(); sqlStatement.sqlConnection = sqlConn; sqlStatement.text = "SELECT * FROM contacts"; sqlStatement.execute(10); ■ You can get the next batch of rows returned by calling the next method on the SQLStatement instance sqlStatement.next();
  • 13. flash.data.SQLResult ■ SQLResult.data - array of objects for each row of the result ■ SQLResult.complete - returns a boolean indicating whether or not the full result was shown ■ SQLResult.lastInsertRowID - return id for the last row that was inserted ■ SQLResult.rowsAffected - number of rows affected by an insert, update or delete operation
  • 14. Transactions ■ Transactions allow multiple SQL statements to run within one write operation to the database ■ Much more optimized way of handling large insert operations, allows rollback of the complete transaction if an error occurs var sqlStatement:SQLStatement = new SQLStatement(); sqlStatement.sqlConnection = sqlConn; sqlStatement.text = "INSERT into contacts VALUES (@NAME, @EMAIL)"; sqlConn.begin(); for(var i:uint=0; i<contacts.length; i++) { sqlStatement.parameters["@NAME"] = contacts[i].name; sqlStatement.parameters["@EMAIL"] = contacts[i].email; sqlStatement.execute(); } sqlConn.commit();
  • 15. Database Schema ■ Allows you to introspect tables, views, columns, indices, triggers var sqlConn:SQLConnection = new SQLConnection(); sqlConn.open(dbFile); sqlConn.loadSchema(); var result:SQLSchemaResult = sqlConn.getSchemaResult(); var table:SQLTableSchema = result.tables[0]; var column:SQLColumnSchema = table.columns[0]; trace(column.name); // returns name of the first column in the first table
  • 17. Database encryption ■ New feature in AIR 1.5 ■ Password protect database files var encryptionKey:ByteArray = new ByteArray(); encryptionKey.writeUTFBytes("notverysecretpassword"); var sqlConn:SQLConnection = new SQLConnection(); sqlConn.open(dbFile,SQLMode.READ,null,false,1024,encryptionKey);
  • 18. Encryption best practices ■ Do not embed passwords in your application! ■ com.adobe.air.crypto.EncryptionKeyGenerator ■ Secure solution: creates random salt and stores in the EncryptedLocalStore (linked to user and machine) ■ Prevents dictionary attack ■ com.dehats.air.sqlite.SimpleEncryptionKeyGenerator ■ Less secure but allows access by other users and other applications, doesn’t generate a random salt value. http://bit.ly/SimpleEncryptionKeyGenerator
  • 19. Database synchronization ■ Synchronize database between server and client(s) ■ Some different strategies ■ overwrite (server overwrites client) ■ check what to synchronize ■ timestamp field ■ field by field comparison ■ dirty flag ■ LiveCycle Data Services has built-in SQLite synchronization support including offline caching and conflict management.
  • 22. Lita - SQLite database administration
  • 23. DAO-Ext - value object generator
  • 24. What is DAO? ■ Data Access Objects - abstract interface to a database ■ implements common features (select, update, delete, ...) ■ Uses value objects (VO)
  • 25. What is DAO? ■ Data Access Objects - abstract interface to a database ■ implements common features (select, update, delete, ...) ■ Uses value objects (VO) ■ Value Objects (also known as Data Transfer Objects) ■ don’t implement any behavior ■ encapsulates properties through getter/setter methods ■ represent an entry in a database table
  • 26. Example VO public class contactsVO { private var _name:String; public function get name():String { return _name; } public function set name(value:String):void { _name = value; } ... }
  • 27. Example DAO public class contactsDAO { public function insertRow(rowItem:contactsVO):void { ... } public function updateRow(rowItem:contactsVO):void { ... } public function deleteRow(rowItem:contactsVO):void { ... } }
  • 29. SQLite wrapper classes ■ Simple way to use SQLite features in your application ■ ActionScript 3.0 classes, primarily for use as tags in MXML <sql:SQLite id="myDB" file="contacts.db" open="myQuery.execute()" /> <sql:Query id="myQuery" connection="{myDB.connection}" sql="SELECT * FROM contacts" /> <mx:DataGrid id="myDataGrid" dataProvider="{myQuery.data}" /> <mx:Button label="Refresh data" click="myQuery.execute()" />
  • 30. SQLite wrapper - SQLite class ■ Properties ■ file - name of database file ■ connection - returns SQLConnection instance ■ Methods ■ open - create database connection ■ close - close database connection ■ Events ■ open - database connection is opened ■ close - database connection is closed ■ error - error connecting to database
  • 31. SQLite wrapper - Query class ■ Properties ■ connection - reference to SQLConnection ■ sql - String value of SQL statement ■ parameters - parameters for SQL statement ■ data - result returned from query ■ Methods ■ execute - run query on database ■ Events ■ result - result received from query ■ error - error executing query
  • 33. Resources ■ Lita - SQLite Administration Tool by David Deraedt www.dehats.com/drupal/?q=node/58 ■ DAO-Ext by Comtaste code.google.com/p/dao-ext/ ■ Adobe AIR Developer Center www.adobe.com/devnet/air/ ■ Adobe AIR Marketplace www.adobe.com/go/airmarketplace
  • 34. Thanks for your time Any questions or feedback - feel free to get in touch! blog www.peterelst.com email [email protected] twitter @peterelst e confe rence! rest o f th En joy the