SlideShare a Scribd company logo
Introduction to SQLite
in Adobe AIR 1.5
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?
How do you use it?
1. Create a File reference
How do you use it?
1. Create a File reference

2. Create an instance of flash.data.SQLConnection and
   flash.data.SQLStatement
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
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
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(quot;contacts.dbquot;);

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

 sqlConn.open(dbFile);

 sqlStatement.sqlConnection = sqlConn;
 sqlStatement.text = quot;SELECT * FROM contactsquot;;
 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
Storage types
■ NULL - NULL value (null)

■ INTEGER - signed integer (int)

■ REAL - floating point (Number)

■ TEXT - UTF16 text string (String)

■ BLOB - blob of data
SQLStatement Parameters
■ The parameters feature protects your SQL statements from
  SQL injection

  var sqlStatement:SQLStatement = new SQLStatement();
  sqlStatement.sqlConnection = sqlConn;
  sqlStatement.text = quot;SELECT * FROM contacts WHERE id = @IDquot;;
  sqlStatement.parameters[quot;@IDquot;] = 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 = quot;SELECT * FROM contactsquot;;
  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 = quot;INSERT into contacts VALUES (@NAME, @EMAIL)quot;;

 sqlConn.begin();
 for(var i:uint=0; i<contacts.length; i++) {
   sqlStatement.parameters[quot;@NAMEquot;] = contacts[i].name;
   sqlStatement.parameters[quot;@EMAILquot;] = 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
Encrypted database support
■ New feature in AIR 1.5

■ Allows you to encrypt the SQLite database

■ ByteArray as an encryption key when opening the
  flash.data.SQLConnection

■ Database must be encrypted when it is created

■ Use SQLConnection.reencrypt([ByteArray]) to change the
  encryption key on a database
Encrypted database support
■ Simple example (not secure)

   var encryptionKey:ByteArray = new ByteArray();
   encryptionKey.writeUTFBytes(quot;notverysecretpasswordquot;);

   var sqlConn:SQLConnection = new SQLConnection();

   sqlConn.openAsync(dbFile, SQLMode.CREATE, null, false, 1024,
   encryptionKey);


■ For additional security:

 ■ Bundle the encrypted database with your AIR app

 ■ Get user input for the password rather than hardcoding it

 ■ Use the EncryptionGenerator class from as3corelib.swc
Demo time
Resources
■ Adobe AIR Developer Center
  www.adobe.com/devnet/air/

■ Adobe AIR 1.5 Cookbook (O'Reilly)

■ www.peterelst.com | info@peterelst.com

More Related Content

What's hot

Android - Saving data
Android - Saving dataAndroid - Saving data
Android - Saving data
Matteo Bonifazi
 
Backendless apps
Backendless appsBackendless apps
Backendless apps
Matteo Bonifazi
 
MySQL Replication Update - DEbconf 2020 presentation
MySQL Replication Update - DEbconf 2020 presentationMySQL Replication Update - DEbconf 2020 presentation
MySQL Replication Update - DEbconf 2020 presentation
Dave Stokes
 
Data management with ado
Data management with adoData management with ado
Data management with adoDinesh kumar
 
Windowsosauthent
WindowsosauthentWindowsosauthent
Windowsosauthent
oracle documents
 
Codemotion 2013: Feliz 15 aniversario, SQL Injection
Codemotion 2013: Feliz 15 aniversario, SQL InjectionCodemotion 2013: Feliz 15 aniversario, SQL Injection
Codemotion 2013: Feliz 15 aniversario, SQL Injection
Chema Alonso
 
Synapse india reviews on php and sql
Synapse india reviews on php and sqlSynapse india reviews on php and sql
Synapse india reviews on php and sql
saritasingh19866
 
cPanel now supports MySQL 8.0 - My Top Seven Features
cPanel now supports MySQL 8.0 - My Top Seven FeaturescPanel now supports MySQL 8.0 - My Top Seven Features
cPanel now supports MySQL 8.0 - My Top Seven Features
Dave Stokes
 
Struts database access
Struts database accessStruts database access
Struts database access
Abass Ndiaye
 
Time-Based Blind SQL Injection Using Heavy Queries
Time-Based Blind SQL Injection Using Heavy QueriesTime-Based Blind SQL Injection Using Heavy Queries
Time-Based Blind SQL Injection Using Heavy Queries
Chema Alonso
 
Architecture Components
Architecture Components Architecture Components
Architecture Components
DataArt
 
MySQL 8.0 New Features -- September 27th presentation for Open Source Summit
MySQL 8.0 New Features -- September 27th presentation for Open Source SummitMySQL 8.0 New Features -- September 27th presentation for Open Source Summit
MySQL 8.0 New Features -- September 27th presentation for Open Source Summit
Dave Stokes
 
Sql server ___________session_18(stored procedures)
Sql server  ___________session_18(stored procedures)Sql server  ___________session_18(stored procedures)
Sql server ___________session_18(stored procedures)
Ehtisham Ali
 
SQL Server 2016 RC3 Always Encryption
SQL Server 2016 RC3 Always Encryption SQL Server 2016 RC3 Always Encryption
SQL Server 2016 RC3 Always Encryption
sultankhan
 
Accessing data with android cursors
Accessing data with android cursorsAccessing data with android cursors
Accessing data with android cursors
info_zybotech
 
Wicket Security Presentation
Wicket Security PresentationWicket Security Presentation
Wicket Security Presentation
mrmean
 
Amazon Cognito使って認証したい?それならSpring Security使いましょう!
Amazon Cognito使って認証したい?それならSpring Security使いましょう!Amazon Cognito使って認証したい?それならSpring Security使いましょう!
Amazon Cognito使って認証したい?それならSpring Security使いましょう!
Ryosuke Uchitate
 

What's hot (19)

Android - Saving data
Android - Saving dataAndroid - Saving data
Android - Saving data
 
Backendless apps
Backendless appsBackendless apps
Backendless apps
 
MySQL Replication Update - DEbconf 2020 presentation
MySQL Replication Update - DEbconf 2020 presentationMySQL Replication Update - DEbconf 2020 presentation
MySQL Replication Update - DEbconf 2020 presentation
 
Data management with ado
Data management with adoData management with ado
Data management with ado
 
Windowsosauthent
WindowsosauthentWindowsosauthent
Windowsosauthent
 
Codemotion 2013: Feliz 15 aniversario, SQL Injection
Codemotion 2013: Feliz 15 aniversario, SQL InjectionCodemotion 2013: Feliz 15 aniversario, SQL Injection
Codemotion 2013: Feliz 15 aniversario, SQL Injection
 
spring-tutorial
spring-tutorialspring-tutorial
spring-tutorial
 
Synapse india reviews on php and sql
Synapse india reviews on php and sqlSynapse india reviews on php and sql
Synapse india reviews on php and sql
 
cPanel now supports MySQL 8.0 - My Top Seven Features
cPanel now supports MySQL 8.0 - My Top Seven FeaturescPanel now supports MySQL 8.0 - My Top Seven Features
cPanel now supports MySQL 8.0 - My Top Seven Features
 
Struts database access
Struts database accessStruts database access
Struts database access
 
Time-Based Blind SQL Injection Using Heavy Queries
Time-Based Blind SQL Injection Using Heavy QueriesTime-Based Blind SQL Injection Using Heavy Queries
Time-Based Blind SQL Injection Using Heavy Queries
 
Architecture Components
Architecture Components Architecture Components
Architecture Components
 
MySQL 8.0 New Features -- September 27th presentation for Open Source Summit
MySQL 8.0 New Features -- September 27th presentation for Open Source SummitMySQL 8.0 New Features -- September 27th presentation for Open Source Summit
MySQL 8.0 New Features -- September 27th presentation for Open Source Summit
 
2nd-Order-SQLi-Josh
2nd-Order-SQLi-Josh2nd-Order-SQLi-Josh
2nd-Order-SQLi-Josh
 
Sql server ___________session_18(stored procedures)
Sql server  ___________session_18(stored procedures)Sql server  ___________session_18(stored procedures)
Sql server ___________session_18(stored procedures)
 
SQL Server 2016 RC3 Always Encryption
SQL Server 2016 RC3 Always Encryption SQL Server 2016 RC3 Always Encryption
SQL Server 2016 RC3 Always Encryption
 
Accessing data with android cursors
Accessing data with android cursorsAccessing data with android cursors
Accessing data with android cursors
 
Wicket Security Presentation
Wicket Security PresentationWicket Security Presentation
Wicket Security Presentation
 
Amazon Cognito使って認証したい?それならSpring Security使いましょう!
Amazon Cognito使って認証したい?それならSpring Security使いましょう!Amazon Cognito使って認証したい?それならSpring Security使いましょう!
Amazon Cognito使って認証したい?それならSpring Security使いましょう!
 

Similar to Introduction to SQLite in Adobe AIR 1.5

Introduction to SQLite in Adobe AIR
Introduction to SQLite in Adobe AIRIntroduction to SQLite in Adobe AIR
Introduction to SQLite in Adobe AIR
Peter Elst
 
Get database properties using power shell in sql server 2008 techrepublic
Get database properties using power shell in sql server 2008   techrepublicGet database properties using power shell in sql server 2008   techrepublic
Get database properties using power shell in sql server 2008 techrepublicKaing Menglieng
 
Windows Azure and a little SQL Data Services
Windows Azure and a little SQL Data ServicesWindows Azure and a little SQL Data Services
Windows Azure and a little SQL Data Services
ukdpe
 
Sql Injection and Entity Frameworks
Sql Injection and Entity FrameworksSql Injection and Entity Frameworks
Sql Injection and Entity FrameworksRich Helton
 
Web Technologies - forms and actions
Web Technologies -  forms and actionsWeb Technologies -  forms and actions
Web Technologies - forms and actionsAren Zomorodian
 
Database Programming Techniques
Database Programming TechniquesDatabase Programming Techniques
Database Programming Techniques
Raji Ghawi
 
Azure SQL Database - Connectivity Best Practices
Azure SQL Database - Connectivity Best PracticesAzure SQL Database - Connectivity Best Practices
Azure SQL Database - Connectivity Best Practices
Jose Manuel Jurado Diaz
 
Database presentation
Database presentationDatabase presentation
Database presentationwebhostingguy
 
JDBC for CSQL Database
JDBC for CSQL DatabaseJDBC for CSQL Database
JDBC for CSQL Database
jitendral
 
General Principles of Web Security
General Principles of Web SecurityGeneral Principles of Web Security
General Principles of Web Security
jemond
 
Asp .Net Database Connectivity Presentation.pptx
Asp .Net Database Connectivity Presentation.pptxAsp .Net Database Connectivity Presentation.pptx
Asp .Net Database Connectivity Presentation.pptx
sridharu1981
 
DIWE - Working with MySQL Databases
DIWE - Working with MySQL DatabasesDIWE - Working with MySQL Databases
DIWE - Working with MySQL Databases
Rasan Samarasinghe
 
Python SQite3 database Tutorial | SQlite Database
Python SQite3 database Tutorial | SQlite DatabasePython SQite3 database Tutorial | SQlite Database
Python SQite3 database Tutorial | SQlite Database
ElangovanTechNotesET
 
Sql injection
Sql injectionSql injection
Sql injection
Mehul Boghra
 
Deeply Declarative Data Pipelines
Deeply Declarative Data PipelinesDeeply Declarative Data Pipelines
Deeply Declarative Data Pipelines
HostedbyConfluent
 
03. sql and other injection module v17
03. sql and other injection module v1703. sql and other injection module v17
03. sql and other injection module v17
Eoin Keary
 
How to connect sql server to oracle server
How to connect sql server to oracle serverHow to connect sql server to oracle server
How to connect sql server to oracle server
Gustavo Bernardo
 

Similar to Introduction to SQLite in Adobe AIR 1.5 (20)

Introduction to SQLite in Adobe AIR
Introduction to SQLite in Adobe AIRIntroduction to SQLite in Adobe AIR
Introduction to SQLite in Adobe AIR
 
Get database properties using power shell in sql server 2008 techrepublic
Get database properties using power shell in sql server 2008   techrepublicGet database properties using power shell in sql server 2008   techrepublic
Get database properties using power shell in sql server 2008 techrepublic
 
Windows Azure and a little SQL Data Services
Windows Azure and a little SQL Data ServicesWindows Azure and a little SQL Data Services
Windows Azure and a little SQL Data Services
 
Sql Injection and Entity Frameworks
Sql Injection and Entity FrameworksSql Injection and Entity Frameworks
Sql Injection and Entity Frameworks
 
Web Technologies - forms and actions
Web Technologies -  forms and actionsWeb Technologies -  forms and actions
Web Technologies - forms and actions
 
Database Programming Techniques
Database Programming TechniquesDatabase Programming Techniques
Database Programming Techniques
 
Azure SQL Database - Connectivity Best Practices
Azure SQL Database - Connectivity Best PracticesAzure SQL Database - Connectivity Best Practices
Azure SQL Database - Connectivity Best Practices
 
Database presentation
Database presentationDatabase presentation
Database presentation
 
JDBC in Servlets
JDBC in ServletsJDBC in Servlets
JDBC in Servlets
 
JDBC for CSQL Database
JDBC for CSQL DatabaseJDBC for CSQL Database
JDBC for CSQL Database
 
General Principles of Web Security
General Principles of Web SecurityGeneral Principles of Web Security
General Principles of Web Security
 
Asp .Net Database Connectivity Presentation.pptx
Asp .Net Database Connectivity Presentation.pptxAsp .Net Database Connectivity Presentation.pptx
Asp .Net Database Connectivity Presentation.pptx
 
Sql injection
Sql injectionSql injection
Sql injection
 
DIWE - Working with MySQL Databases
DIWE - Working with MySQL DatabasesDIWE - Working with MySQL Databases
DIWE - Working with MySQL Databases
 
JDBC – Java Database Connectivity
JDBC – Java Database ConnectivityJDBC – Java Database Connectivity
JDBC – Java Database Connectivity
 
Python SQite3 database Tutorial | SQlite Database
Python SQite3 database Tutorial | SQlite DatabasePython SQite3 database Tutorial | SQlite Database
Python SQite3 database Tutorial | SQlite Database
 
Sql injection
Sql injectionSql injection
Sql injection
 
Deeply Declarative Data Pipelines
Deeply Declarative Data PipelinesDeeply Declarative Data Pipelines
Deeply Declarative Data Pipelines
 
03. sql and other injection module v17
03. sql and other injection module v1703. sql and other injection module v17
03. sql and other injection module v17
 
How to connect sql server to oracle server
How to connect sql server to oracle serverHow to connect sql server to oracle server
How to connect sql server to oracle server
 

More from Peter Elst

P2P on the local network
P2P on the local networkP2P on the local network
P2P on the local network
Peter Elst
 
P2P with Flash Player 10.1
P2P with Flash Player 10.1P2P with Flash Player 10.1
P2P with Flash Player 10.1Peter Elst
 
Big boys and their litl toys
Big boys and their litl toysBig boys and their litl toys
Big boys and their litl toysPeter Elst
 
Yes, you can do that with AIR 2.0
Yes, you can do that with AIR 2.0Yes, you can do that with AIR 2.0
Yes, you can do that with AIR 2.0
Peter Elst
 
FATC - AIR 2.0 workshop
FATC - AIR 2.0 workshopFATC - AIR 2.0 workshop
FATC - AIR 2.0 workshopPeter Elst
 
Developing with Adobe AIR
Developing with Adobe AIRDeveloping with Adobe AIR
Developing with Adobe AIR
Peter Elst
 
Introduction to AS3Signals
Introduction to AS3SignalsIntroduction to AS3Signals
Introduction to AS3SignalsPeter Elst
 
The Secret Life of a Flash Freelancer
The Secret Life of a Flash FreelancerThe Secret Life of a Flash Freelancer
The Secret Life of a Flash FreelancerPeter Elst
 
Getting Creative with Adobe AIR
Getting Creative with Adobe AIRGetting Creative with Adobe AIR
Getting Creative with Adobe AIRPeter Elst
 
Creative Programming in ActionScript 3.0
Creative Programming in ActionScript 3.0Creative Programming in ActionScript 3.0
Creative Programming in ActionScript 3.0Peter Elst
 
RIA meets Desktop
RIA meets DesktopRIA meets Desktop
RIA meets DesktopPeter Elst
 
Object-Oriented ActionScript 3.0
Object-Oriented ActionScript 3.0Object-Oriented ActionScript 3.0
Object-Oriented ActionScript 3.0Peter Elst
 
The Evolution of the Flash Platform
The Evolution of the Flash PlatformThe Evolution of the Flash Platform
The Evolution of the Flash PlatformPeter Elst
 
RIA meets Desktop
RIA meets DesktopRIA meets Desktop
RIA meets Desktop
Peter Elst
 
SkillsMatter - In-the-Brain session - What's new in ActionScript 3.0
SkillsMatter - In-the-Brain session - What's new in ActionScript 3.0SkillsMatter - In-the-Brain session - What's new in ActionScript 3.0
SkillsMatter - In-the-Brain session - What's new in ActionScript 3.0
Peter Elst
 

More from Peter Elst (15)

P2P on the local network
P2P on the local networkP2P on the local network
P2P on the local network
 
P2P with Flash Player 10.1
P2P with Flash Player 10.1P2P with Flash Player 10.1
P2P with Flash Player 10.1
 
Big boys and their litl toys
Big boys and their litl toysBig boys and their litl toys
Big boys and their litl toys
 
Yes, you can do that with AIR 2.0
Yes, you can do that with AIR 2.0Yes, you can do that with AIR 2.0
Yes, you can do that with AIR 2.0
 
FATC - AIR 2.0 workshop
FATC - AIR 2.0 workshopFATC - AIR 2.0 workshop
FATC - AIR 2.0 workshop
 
Developing with Adobe AIR
Developing with Adobe AIRDeveloping with Adobe AIR
Developing with Adobe AIR
 
Introduction to AS3Signals
Introduction to AS3SignalsIntroduction to AS3Signals
Introduction to AS3Signals
 
The Secret Life of a Flash Freelancer
The Secret Life of a Flash FreelancerThe Secret Life of a Flash Freelancer
The Secret Life of a Flash Freelancer
 
Getting Creative with Adobe AIR
Getting Creative with Adobe AIRGetting Creative with Adobe AIR
Getting Creative with Adobe AIR
 
Creative Programming in ActionScript 3.0
Creative Programming in ActionScript 3.0Creative Programming in ActionScript 3.0
Creative Programming in ActionScript 3.0
 
RIA meets Desktop
RIA meets DesktopRIA meets Desktop
RIA meets Desktop
 
Object-Oriented ActionScript 3.0
Object-Oriented ActionScript 3.0Object-Oriented ActionScript 3.0
Object-Oriented ActionScript 3.0
 
The Evolution of the Flash Platform
The Evolution of the Flash PlatformThe Evolution of the Flash Platform
The Evolution of the Flash Platform
 
RIA meets Desktop
RIA meets DesktopRIA meets Desktop
RIA meets Desktop
 
SkillsMatter - In-the-Brain session - What's new in ActionScript 3.0
SkillsMatter - In-the-Brain session - What's new in ActionScript 3.0SkillsMatter - In-the-Brain session - What's new in ActionScript 3.0
SkillsMatter - In-the-Brain session - What's new in ActionScript 3.0
 

Recently uploaded

Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 

Recently uploaded (20)

Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 

Introduction to SQLite in Adobe AIR 1.5

  • 1. Introduction to SQLite in Adobe AIR 1.5 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?
  • 4. How do you use it? 1. Create a File reference
  • 5. How do you use it? 1. Create a File reference 2. Create an instance of flash.data.SQLConnection and flash.data.SQLStatement
  • 6. 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
  • 7. 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
  • 8. 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()
  • 9. How do you use it? import flash.filesystem.File; import flash.data.*; var dbFile:File = File.applicationStorageDirectory.resolvePath(quot;contacts.dbquot;); var sqlConn:SQLConnection = new SQLConnection(); var sqlStatement:SQLStatement = new SQLStatement(); sqlConn.open(dbFile); sqlStatement.sqlConnection = sqlConn; sqlStatement.text = quot;SELECT * FROM contactsquot;; sqlStatement.execute(); var result:Array = sqlStatement.getResult().data;
  • 10. 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);
  • 11. flash.data.SQLConnection ■ Connects to the database file ■ Provides events for asynchronous use ■ Schema access
  • 12. flash.data.SQLStatement ■ Executes a SQL query on the specified database connection ■ Provides events for asynchronous use ■ Supports result paging
  • 13. Storage types ■ NULL - NULL value (null) ■ INTEGER - signed integer (int) ■ REAL - floating point (Number) ■ TEXT - UTF16 text string (String) ■ BLOB - blob of data
  • 14. SQLStatement Parameters ■ The parameters feature protects your SQL statements from SQL injection var sqlStatement:SQLStatement = new SQLStatement(); sqlStatement.sqlConnection = sqlConn; sqlStatement.text = quot;SELECT * FROM contacts WHERE id = @IDquot;; sqlStatement.parameters[quot;@IDquot;] = 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;
  • 15. 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 = quot;SELECT * FROM contactsquot;; sqlStatement.execute(10); ■ You can get the next batch of rows returned by calling the next method on the SQLStatement instance sqlStatement.next();
  • 16. 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
  • 17. 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 = quot;INSERT into contacts VALUES (@NAME, @EMAIL)quot;; sqlConn.begin(); for(var i:uint=0; i<contacts.length; i++) { sqlStatement.parameters[quot;@NAMEquot;] = contacts[i].name; sqlStatement.parameters[quot;@EMAILquot;] = contacts[i].email; sqlStatement.execute(); } sqlConn.commit();
  • 18. 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
  • 19. Encrypted database support ■ New feature in AIR 1.5 ■ Allows you to encrypt the SQLite database ■ ByteArray as an encryption key when opening the flash.data.SQLConnection ■ Database must be encrypted when it is created ■ Use SQLConnection.reencrypt([ByteArray]) to change the encryption key on a database
  • 20. Encrypted database support ■ Simple example (not secure) var encryptionKey:ByteArray = new ByteArray(); encryptionKey.writeUTFBytes(quot;notverysecretpasswordquot;); var sqlConn:SQLConnection = new SQLConnection(); sqlConn.openAsync(dbFile, SQLMode.CREATE, null, false, 1024, encryptionKey); ■ For additional security: ■ Bundle the encrypted database with your AIR app ■ Get user input for the password rather than hardcoding it ■ Use the EncryptionGenerator class from as3corelib.swc
  • 22. Resources ■ Adobe AIR Developer Center www.adobe.com/devnet/air/ ■ Adobe AIR 1.5 Cookbook (O'Reilly) ■ www.peterelst.com | info@peterelst.com