SQLite in Adobe AIR

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    10 Favorites

    SQLite in Adobe AIR - Presentation Transcript

    1. SQLite in Adobe AIR Peter Elst | May 23th 2008 - 2M08
    2. Why SQLite in Adobe AIR?
    3. Why SQLite in Adobe AIR?
    4. Why Koen?
    5. Why Koen?
    6. Why SQLite in Adobe AIR?
    7. Why SQLite in Adobe AIR? Embedded SQL Database Engine
    8. Why SQLite in Adobe AIR? Embedded SQL Database Engine Implements most of SQL92
    9. Why SQLite in Adobe AIR? Embedded SQL Database Engine Implements most of SQL92 Light-weight, cross-platform, open source
    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
    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
    12. How do you use it?
    13. How do you use it? 1.Create a File reference
    14. How do you use it? 1.Create a File reference 2.Create an instance of flash.data.SQLConnection and flash.data.SQLStatement
    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
    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
    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()
    18. How do you use it?
    19. How do you use it? import flash.filesystem.File; import flash.data.*; var dbFile:File = File.applicationStorageDirectory. ↵ resolvePath(\"contacts.db\");
    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();
    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);
    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\";
    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;
    24. Synchronous versus Async
    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;
    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);
    27. flash.data.SQLConnection
    28. flash.data.SQLConnection Connects to the database file
    29. flash.data.SQLConnection Connects to the database file Provides events for asynchronous use
    30. flash.data.SQLConnection Connects to the database file Provides events for asynchronous use Schema access
    31. flash.data.SQLStatement
    32. flash.data.SQLStatement Executes a SQL query on the specified database connection
    33. flash.data.SQLStatement Executes a SQL query on the specified database connection Provides events for asynchronous use
    34. flash.data.SQLStatement Executes a SQL query on the specified database connection Provides events for asynchronous use Supports result paging
    35. Storage types
    36. Storage types NULL - NULL value (null)
    37. Storage types NULL - NULL value (null) INTEGER - signed integer (int)
    38. Storage types NULL - NULL value (null) INTEGER - signed integer (int) REAL - floating point (Number)
    39. Storage types NULL - NULL value (null) INTEGER - signed integer (int) REAL - floating point (Number) TEXT - UTF16 text string (String)
    40. Storage types NULL - NULL value (null) INTEGER - signed integer (int) REAL - floating point (Number) TEXT - UTF16 text string (String) BLOB - blob of data
    41. SQLStatement Parameters
    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();
    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;
    44. SQLStatement Parameters
    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();
    46. Result Paging
    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);
    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();
    49. flash.data.SQLResult
    50. flash.data.SQLResult SQLResult.data - array of objects for each row of the result
    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
    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
    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
    54. Transactions
    55. Transactions Transactions allow multiple SQL statements to run within one write operation to the database
    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
    57. Transactions
    58. Transactions var sqlStatement:SQLStatement = new SQLStatement(); sqlStatement.sqlConnection = sqlConn; sqlStatement.text = \"INSERT into contacts VALUES (@NAME, @EMAIL)\";
    59. Transactions var sqlStatement:SQLStatement = new SQLStatement(); sqlStatement.sqlConnection = sqlConn; sqlStatement.text = \"INSERT into contacts VALUES (@NAME, @EMAIL)\"; sqlConn.begin();
    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(); }
    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();
    62. Database schema
    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
    64. SQLite wrapper classes
    65. SQLite wrapper classes You can use ActionScript 3.0 classes as MXML tags
    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}\" />
    67. SQLite synchronisation
    68. SQLite synchronisation Synchronizing an online and offline SQLite database
    69. SQLite synchronisation Synchronizing an online and offline SQLite database Different strategies
    70. SQLite synchronisation Synchronizing an online and offline SQLite database Different strategies Online database overwrites offline
    71. SQLite synchronisation Synchronizing an online and offline SQLite database Different strategies Online database overwrites offline Check timestamp on each row, new overwrites old
    72. Demo time
    73. Demo time Contact Manager
    74. Demo time Contact Manager SQLite Editor
    75. Demo time Contact Manager SQLite Editor YouTube Database
    76. Demo time Contact Manager SQLite Editor YouTube Database HTML/JavaScript + SQLite
    77. SQLite on Mac OSX
    78. Resources
    79. Resources www.adobe.com/devnet/air/
    80. Resources www.adobe.com/devnet/air/ onair.adobe.com
    81. Resources www.adobe.com/devnet/air/ onair.adobe.com www.30onair.com
    82. Resources www.adobe.com/devnet/air/ onair.adobe.com www.30onair.com www.peterelst.com
    83. Resources www.adobe.com/devnet/air/ onair.adobe.com www.30onair.com www.peterelst.com Introduction to SQLite in Adobe AIR
    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
    85. Contact me
    86. Contact me Questions, comments, feedback?
    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
    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!

    + Peter ElstPeter Elst, 2 years ago

    custom

    7764 views, 10 favs, 3 embeds more stats

    More info about this document

    CC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike License

    Go to text version

    • Total Views 7764
      • 7585 on SlideShare
      • 179 from embeds
    • Comments 0
    • Favorites 10
    • Downloads 210
    Most viewed embeds
    • 112 views on http://www.napolux.com
    • 57 views on http://www.peterelst.com
    • 10 views on http://xss.yandex.net

    more

    All embeds
    • 112 views on http://www.napolux.com
    • 57 views on http://www.peterelst.com
    • 10 views on http://xss.yandex.net

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories