Slideshare.net (beta)

 
Post to TwitterPost to Twitter
Post: 
Myspace Hi5 Friendster Xanga LiveJournal Facebook Blogger Tagged Typepad Freewebs BlackPlanet gigya icons

All comments

Add a comment on Slide 1

If you have a SlideShare account, login to comment; else you can comment as a guest


Showing 1-50 of 5 (more)

SQLite in Adobe AIR

From peterelst, 4 months ago

2268 views  |  0 comments  |  5 favorites  |  80 downloads  |  2 embeds (Stats)
 

Categories

Add Category
 
 

Groups / Events

 

 
Embed
options

More Info

CC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike License
This slideshow is Public
Total Views: 2268
on Slideshare: 2119
from embeds: 149

Slideshow transcript

Slide 1: SQLite in Adobe AIR Peter Elst | May 23th 2008 - 2M08

Slide 2: Why SQLite in Adobe AIR?

Slide 3: Why SQLite in Adobe AIR?

Slide 4: Why Koen?

Slide 5: Why Koen?

Slide 6: Why SQLite in Adobe AIR?

Slide 7: Why SQLite in Adobe AIR? Embedded SQL Database Engine

Slide 8: Why SQLite in Adobe AIR? Embedded SQL Database Engine Implements most of SQL92

Slide 9: Why SQLite in Adobe AIR? Embedded SQL Database Engine Implements most of SQL92 Light-weight, cross-platform, open source

Slide 10: 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

Slide 11: 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

Slide 12: How do you use it?

Slide 13: How do you use it? 1.Create a File reference

Slide 14: How do you use it? 1.Create a File reference 2.Create an instance of flash.data.SQLConnection and flash.data.SQLStatement

Slide 15: 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

Slide 16: 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

Slide 17: 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()

Slide 18: How do you use it?

Slide 19: How do you use it? import flash.filesystem.File; import flash.data.*; var dbFile:File = File.applicationStorageDirectory. ↵ resolvePath(\"contacts.db\");

Slide 20: 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();

Slide 21: 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);

Slide 22: 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\";

Slide 23: 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;

Slide 24: Synchronous versus Async

Slide 25: Synchronous versus Async Synchronous - blocks application until result is available var sqlConn:SQLConnection = new SQLConnection(); sqlConn.open(dbFile); var result:SQLResult = sqlConn.getResult().result;

Slide 26: Synchronous versus Async 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);

Slide 27: flash.data.SQLConnection

Slide 28: flash.data.SQLConnection Connects to the database file

Slide 29: flash.data.SQLConnection Connects to the database file Provides events for asynchronous use

Slide 30: flash.data.SQLConnection Connects to the database file Provides events for asynchronous use Schema access

Slide 31: flash.data.SQLStatement

Slide 32: flash.data.SQLStatement Executes a SQL query on the specified database connection

Slide 33: flash.data.SQLStatement Executes a SQL query on the specified database connection Provides events for asynchronous use

Slide 34: flash.data.SQLStatement Executes a SQL query on the specified database connection Provides events for asynchronous use Supports result paging

Slide 35: Storage types

Slide 36: Storage types NULL - NULL value (null)

Slide 37: Storage types NULL - NULL value (null) INTEGER - signed integer (int)

Slide 38: Storage types NULL - NULL value (null) INTEGER - signed integer (int) REAL - floating point (Number)

Slide 39: Storage types NULL - NULL value (null) INTEGER - signed integer (int) REAL - floating point (Number) TEXT - UTF16 text string (String)

Slide 40: Storage types NULL - NULL value (null) INTEGER - signed integer (int) REAL - floating point (Number) TEXT - UTF16 text string (String) BLOB - blob of data

Slide 41: SQLStatement Parameters

Slide 42: 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();

Slide 43: 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 : character to denote a parameter to be replaced sqlStatement.parameters[\":NAME\"] = someVariable;

Slide 44: SQLStatement Parameters

Slide 45: SQLStatement Parameters Using the ? character you can have unnamed parameters and an index based array var sqlStatement:SQLStatement = new SQLStatement(); sqlStatement.sqlConnection = sqlConn; sqlStatement.text = \"SELECT * FROM contacts WHERE name = ? ↵ AND lastname = ?\"; sqlStatement.parameters[0] = \"Peter\"; sqlStatement.parameters[1] = \"Elst\"; sqlStatement.execute();

Slide 46: Result Paging

Slide 47: 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);

Slide 48: 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();

Slide 49: flash.data.SQLResult

Slide 50: flash.data.SQLResult SQLResult.data - array of objects for each row of the result

Slide 51: 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

Slide 52: 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

Slide 53: 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

Slide 54: Transactions

Slide 55: Transactions Transactions allow multiple SQL statements to run within one write operation to the database

Slide 56: 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

Slide 57: Transactions

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

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

Slide 60: Transactions 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(); }

Slide 61: Transactions 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();

Slide 62: Database schema

Slide 63: 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

Slide 64: SQLite wrapper classes

Slide 65: SQLite wrapper classes You can use ActionScript 3.0 classes as MXML tags

Slide 66: SQLite wrapper classes You can use ActionScript 3.0 classes as MXML tags SQLite and Query classes <sql:SQLite id=\"db_conn\" file=\"contacts.db\" open=\"contacts_query.execute()\" /> <sql:Query id=\"contacts_query\" connection=\"{db_conn}\" sql=\"SELECT * FROM contacts\" /> <mx:DataGrid id=\"contacts_dg\" dataProvider=\"{contacts_query.data}\" />

Slide 67: SQLite synchronisation

Slide 68: SQLite synchronisation Synchronizing an online and offline SQLite database

Slide 69: SQLite synchronisation Synchronizing an online and offline SQLite database Different strategies

Slide 70: SQLite synchronisation Synchronizing an online and offline SQLite database Different strategies Online database overwrites offline

Slide 71: SQLite synchronisation Synchronizing an online and offline SQLite database Different strategies Online database overwrites offline Check timestamp on each row, new overwrites old

Slide 72: Demo time

Slide 73: Demo time Contact Manager

Slide 74: Demo time Contact Manager SQLite Editor

Slide 75: Demo time Contact Manager SQLite Editor YouTube Database

Slide 76: Demo time Contact Manager SQLite Editor YouTube Database HTML/JavaScript + SQLite

Slide 77: SQLite on Mac OSX

Slide 78: Resources

Slide 79: Resources www.adobe.com/devnet/air/

Slide 80: Resources www.adobe.com/devnet/air/ onair.adobe.com

Slide 81: Resources www.adobe.com/devnet/air/ onair.adobe.com www.30onair.com

Slide 82: Resources www.adobe.com/devnet/air/ onair.adobe.com www.30onair.com www.peterelst.com

Slide 83: Resources www.adobe.com/devnet/air/ onair.adobe.com www.30onair.com www.peterelst.com Introduction to SQLite in Adobe AIR

Slide 84: Resources www.adobe.com/devnet/air/ onair.adobe.com www.30onair.com www.peterelst.com Introduction to SQLite in Adobe AIR AIR Badge WordPress plugin

Slide 85: Contact me

Slide 86: Contact me Questions, comments, feedback?

Slide 87: Contact me Questions, comments, feedback? Email: info@peterelst.com Blog: www.peterelst.com Twitter: www.twitter.com/peterelst LinkedIn: www.linkedin.com/in/peterelst

Slide 88: Contact me Questions, comments, feedback? Email: info@peterelst.com Blog: www.peterelst.com Twitter: www.twitter.com/peterelst LinkedIn: www.linkedin.com/in/peterelst Thanks and enjoy the rest of the day!