SQLite &                            Titanium                             Who, How & Where          #TiLon                 ...
About                            Ketan Majmudar                            @ketan (twitter)                            spi...
What is SQLite           SQLite is a software library that             implements a self-contained,      serverless,zero-c...
What is SQLite           SQLite is a software library that             implements a self-contained,             SQLite is ...
What is SQLite           SQLite is a software library that             implements a self-contained,      serverless,zero-c...
What is SQLite           SQLite is a software library that             implements a self-contained,      serverless,zero-c...
What is SQLite           SQLite is a software library that             implements a self-contained,      serverless,zero-c...
SQL Brief History                 Based on RDBMS - Relational                 Database Management System based            ...
Ti.Database            OPEN / INSTALL / REMOVE                 EXECUTE Query                       lastInsertRowId        ...
Table/DB Creation                                                                       Create In GUI/         Create In A...
Basic DB usage     // OPEN / INSTALL DATABASE -- SAFE     var db = Ti.Database.install(/mydata/dynamicdata.sqlite, dynamic...
TRANSACTION     // OPEN / INSTALL DATABASE -- SAFE     var db = Ti.Database.install(/mydata/dynamicdata.sqlite, dynamicdat...
Android SQLite                experiment                      APK - download link:    https://dl.dropbox.com/s/8h951ltd80r...
SQLite Versions                          What ships on a device: look at these tables.                                Supp...
button1.addEventListener(click, function(){   	 var alertDialog = Ti.UI.createAlertDialog({   	 	 title: SQLite version ch...
ORMs                            Object Relational Mapping                            Apps need to scale                   ...
SQLite thoughts                            extension not required     TRANSACTIONS &                                      ...
SQLite Editors                            Base                            MesaSQLite                            RazorSQL  ...
http://www.sqlite.org            http://wiki.appcelerator.org            http://developer.appcelerator.com/apidoc/mobile/l...
Upcoming SlideShare
Loading in …5
×

SQLite - Dynamic Data in Titanium

5,419 views

Published on

Talk delivered to the London Titanium User Group meeting in Nov 2011. An overview of SQLite as a RDBMS and how it can be used to do simple stuff in Appcelerator's Titanium mobile development platform.

Published in: Technology, Education
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,419
On SlideShare
0
From Embeds
0
Number of Embeds
26
Actions
Shares
0
Downloads
51
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

SQLite - Dynamic Data in Titanium

  1. 1. SQLite & Titanium Who, How & Where #TiLon London Titanium - Nov 2011 @ketanThursday, 1 December 2011
  2. 2. About Ketan Majmudar @ketan (twitter) spiritquest.co.uk stereoartist.com freakshowuk.com #TiLon London Titanium - Nov 2011 @ketanThursday, 1 December 2011
  3. 3. What is SQLite SQLite is a software library that implements a self-contained, serverless,zero-configuration, transactional SQL database engine. Serverless Open Source Compact #TiLon London Titanium - Nov 2011 @ketanThursday, 1 December 2011
  4. 4. What is SQLite SQLite is a software library that implements a self-contained, SQLite is an embedded SQL serverless,zero-configuration, transactional database engine. Unlike most SQL database engine. other SQL databases, SQLite does not have a separate server process. SQLite reads and writes Serverless directly to ordinary disk files. Open Source Compact #TiLon London Titanium - Nov 2011 @ketanThursday, 1 December 2011
  5. 5. What is SQLite SQLite is a software library that implements a self-contained, serverless,zero-configuration, transactional SQL database engine. The code for SQLite is in the public domain and is thus free Serverless for use for any purpose, commercial or private. SQLite is Open Source currently found in more applications than we can count Compact including several high-profile projects. #TiLon London Titanium - Nov 2011 @ketanThursday, 1 December 2011
  6. 6. What is SQLite SQLite is a software library that implements a self-contained, serverless,zero-configuration, transactional SQL database engine. Serverless Open Source SQLite is a compact library. Compact With all features enabled, the library size can be less than 350KiB, depending on the target platform and compiler optimization settings. #TiLon London Titanium - Nov 2011 @ketanThursday, 1 December 2011
  7. 7. What is SQLite SQLite is a software library that implements a self-contained, serverless,zero-configuration, transactional SQL database engine. Serverless Open Source Compact #TiLon London Titanium - Nov 2011 @ketanThursday, 1 December 2011
  8. 8. SQL Brief History Based on RDBMS - Relational Database Management System based around Edgar F. Codd’s Relational Model Implements most of the SQL-92 standard. Written by D. Richard Hipp in 2000 #TiLon London Titanium - Nov 2011 @ketanThursday, 1 December 2011
  9. 9. Ti.Database OPEN / INSTALL / REMOVE EXECUTE Query lastInsertRowId rowsAffected RESULT Sets isValidRow next #TiLon London Titanium - Nov 2011 @ketanThursday, 1 December 2011
  10. 10. Table/DB Creation Create In GUI/ Create In App Create via console Preload CREATE TABLE "tbl1" ( "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "rowValue" text ) SQLite Database #TiLon London Titanium - Nov 2011 @ketanThursday, 1 December 2011
  11. 11. Basic DB usage // OPEN / INSTALL DATABASE -- SAFE var db = Ti.Database.install(/mydata/dynamicdata.sqlite, dynamicdata); // RESULT SET OBJECT var rs = db.execute(select * from tbl1); alert(Rows in table: + rs.rowCount); while(rs.isValidRow()){ Ti.API.info(rs.field(0) + : + rs.field(1)); rs.next(); } rs.close(); db.execute(INSERT into tbl1 (rowValue) values(date("now"))); alert(Last Insert ID: + db.lastInsertRowId); // CLOSE DATABASE OBJECT db.close(); https://gist.github.com/1401196 #TiLon London Titanium - Nov 2011 @ketanThursday, 1 December 2011
  12. 12. TRANSACTION // OPEN / INSTALL DATABASE -- SAFE var db = Ti.Database.install(/mydata/dynamicdata.sqlite, dynamicdata); // RESULT SET OBJECT var rs = db.execute(select * from tbl1); alert(Rows in table: + rs.rowCount); while(rs.isValidRow()){ Ti.API.info(rs.field(0) + : + rs.field(1)); rs.next(); } rs.close(); db.execute(BEGIN TRANSACTION); try{ db.execute(INSERT into tbl1 (rowValue) values(date("now"))); db.execute(INSERT into tbl1 (rowValues) values(?), new Date().getDate()); alert(Last Insert ID: + db.lastInsertRowId); } catch(e){ alert(e.message); } db.execute(END TRANSACTION); // CLOSE DATABASE OBJECT db.close(); https://gist.github.com/1401366 #TiLon London Titanium - Nov 2011 @ketanThursday, 1 December 2011
  13. 13. Android SQLite experiment APK - download link: https://dl.dropbox.com/s/8h951ltd80rdyig/app.apk?dl=1 #TiLon London Titanium - Nov 2011 @ketanThursday, 1 December 2011
  14. 14. SQLite Versions What ships on a device: look at these tables. Supposedly ships with Android: SQLite version Device OS SQLite version Device OS 3.5.9 Android 1.5-Cupcake 3.4.0 iPhone OS 2.2.1 3.5.9 Android 1.6-Donut 3.5.9 Android 2.1-Eclair 3.6.12 iPhone OS 3.0 / 3.1 3.6.22 Android 2.2-Froyo 3.6.22 Android 2.3.1-Gingerbread 3.6.22 iPhone OS 4.0 3.6.22 Android 2.3.3-Gingerbread 3.7.4 Android 3.0-Honeycomb 3.7.2 iPhone OS 4.3 3.7.4 Android 3.1-Honeycomb 3.7.4 Android 3.2-Honeycomb 3.7.7 iPhone OS 5.0 3.7.4 Android 4.0-Ice Cream Sandwich 3.5.9 2.1-update1 V9 3.6.22 2.2 HTC Desire 3.6.22 2.2.1 HTC Wildfire 3.6.22 2.2.1 HTC Magic 3.7.2 2.3.3 Desire HD 3.7.2 2.3.3 LG-P500 3.7.2 2.3.3 Desire HD 3.7.2 2.3.3 Nexus One 3.6.22 2.3.3 GT-I9100 3.7.2 2.3.3 HTC Wildfire S A510e 3.7.2 2.3.4 HTC Sensation Z710e 3.7.4 3.2 G100W 3.7.4 4.0.1 Galaxy Nexus #TiLon London Titanium - Nov 2011 @ketanThursday, 1 December 2011
  15. 15. button1.addEventListener(click, function(){ var alertDialog = Ti.UI.createAlertDialog({ title: SQLite version check, message: "You are running SQLite " + result.field(0) + " on: " + Ti.Platform.name + + Ti.Platform.version + + Ti.Platform.model + nnPlease consider emailing this to me to build a reference resource of android OS to SQLite versions, csvData: result.field(0) + "," + Ti.Platform.name + , + Ti.Platform.version + , + Ti.Platform.model+,+new Date().getTime(), buttonNames: [No Thanks, OK] }); alertDialog.show(); alertDialog.addEventListener(click, function(e){ if(e.index === 1){ var emailKet = Ti.UI.createEmailDialog({ messageBody: Email Text, toRecipients: [info@spiritquest.co.uk], subject: SQLite android data gathering - London Titanium }); emailKet.open(); } }); }); var db = Ti.Database.open(testData1); var result = db.execute("SELECT sqlite_version();"); https://gist.github.com/1401186 #TiLon London Titanium - Nov 2011 @ketanThursday, 1 December 2011
  16. 16. ORMs Object Relational Mapping Apps need to scale joli.js - Codestrong talk by Xavier Lacot #TiLon London Titanium - Nov 2011 @ketanThursday, 1 December 2011
  17. 17. SQLite thoughts extension not required TRANSACTIONS & ROLLBACKS DB stored in application data directory BLOBS in SQLite have ROLLBACK protection. BLOBS good for files 10-30Kb based on Good for cache SQLite version management. optimise fields: INTEGERS, TEXT then BLOB (table create order) #TiLon London Titanium - Nov 2011 @ketanThursday, 1 December 2011
  18. 18. SQLite Editors Base MesaSQLite RazorSQL SQLite Database Browser Firefox Browser extension Command Line #TiLon London Titanium - Nov 2011 @ketanThursday, 1 December 2011
  19. 19. http://www.sqlite.org http://wiki.appcelerator.org http://developer.appcelerator.com/apidoc/mobile/latest/ http://www.sqlite.org/changes.html @ketan on twitter - www.stereoartist.com/blog Thank You #TiLon London Titanium - Nov 2011 @ketanThursday, 1 December 2011

×