SlideShare ist ein Scribd-Unternehmen logo
1 von 22
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

Weitere ähnliche Inhalte

Was ist angesagt?

MySQL Replication Update - DEbconf 2020 presentation
MySQL Replication Update - DEbconf 2020 presentationMySQL Replication Update - DEbconf 2020 presentation
MySQL Replication Update - DEbconf 2020 presentationDave Stokes
 
Data management with ado
Data management with adoData management with ado
Data management with adoDinesh kumar
 
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 InjectionChema 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 sqlsaritasingh19866
 
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 FeaturesDave Stokes
 
Struts database access
Struts database accessStruts database access
Struts database accessAbass 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 QueriesChema 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 SummitDave 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 cursorsinfo_zybotech
 
Wicket Security Presentation
Wicket Security PresentationWicket Security Presentation
Wicket Security Presentationmrmean
 
Amazon Cognito使って認証したい?それならSpring Security使いましょう!
Amazon Cognito使って認証したい?それならSpring Security使いましょう!Amazon Cognito使って認証したい?それならSpring Security使いましょう!
Amazon Cognito使って認証したい?それならSpring Security使いましょう!Ryosuke Uchitate
 

Was ist angesagt? (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使いましょう!
 

Ähnlich wie 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 AIRPeter 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 Servicesukdpe
 
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 TechniquesRaji Ghawi
 
Azure SQL Database - Connectivity Best Practices
Azure SQL Database - Connectivity Best PracticesAzure SQL Database - Connectivity Best Practices
Azure SQL Database - Connectivity Best PracticesJose Manuel Jurado Diaz
 
Database presentation
Database presentationDatabase presentation
Database presentationwebhostingguy
 
JDBC for CSQL Database
JDBC for CSQL DatabaseJDBC for CSQL Database
JDBC for CSQL Databasejitendral
 
General Principles of Web Security
General Principles of Web SecurityGeneral Principles of Web Security
General Principles of Web Securityjemond
 
Asp .Net Database Connectivity Presentation.pptx
Asp .Net Database Connectivity Presentation.pptxAsp .Net Database Connectivity Presentation.pptx
Asp .Net Database Connectivity Presentation.pptxsridharu1981
 
DIWE - Working with MySQL Databases
DIWE - Working with MySQL DatabasesDIWE - Working with MySQL Databases
DIWE - Working with MySQL DatabasesRasan Samarasinghe
 
Python SQite3 database Tutorial | SQlite Database
Python SQite3 database Tutorial | SQlite DatabasePython SQite3 database Tutorial | SQlite Database
Python SQite3 database Tutorial | SQlite DatabaseElangovanTechNotesET
 
Deeply Declarative Data Pipelines
Deeply Declarative Data PipelinesDeeply Declarative Data Pipelines
Deeply Declarative Data PipelinesHostedbyConfluent
 
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 v17Eoin 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 serverGustavo Bernardo
 

Ähnlich wie 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
 

Mehr von Peter Elst

P2P on the local network
P2P on the local networkP2P on the local network
P2P on the local networkPeter 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.0Peter 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 AIRPeter 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 DesktopPeter 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.0Peter Elst
 

Mehr von 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
 

Kürzlich hochgeladen

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 

Kürzlich hochgeladen (20)

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 

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