Your SlideShare is downloading. ×
  • Like
  • Save
Mobile Application Development: Lecture 15
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.


Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Mobile Application Development: Lecture 15



Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads


Total Views
On SlideShare
From Embeds
Number of Embeds



Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide


  • 1. Mobile Application Development Lecture 15 Vladimir Kulyukin Department of Computer Science Utah State University
  • 2. Outline ● SQLite Data Types ● SQLite Database Construction – Object-Oriented Data Modeling – XML Specifications of DB Tables – Design & Implementation of SQLite Database Adapters – DB Population with Database Adapters
  • 3. SQLite Data Types
  • 4. SQL vs SQLite Data Typing ● SQL engines typically use static typing: datatype of a value is determined by the column in which the value is stored ● SQLite engines use dynamic typing: datatype of a value is associated with the value not the column in which it is stored ● Basic SQL vs. SQLite tradeoff: security and safety (SQL) vs. flexibility (SQLite) ● SQLite rule of thumb: do not expose your SQLite API to third parties
  • 5. SQLite Datatypes ● NULL – the value is NULL ● INTEGER – signed integers; signed integer can be stored as 1, 2, 3, 4, 5, 6, or 8 bytes; the storage size depends on the value magnitude ● REAL – float-point numbers; stored as 8 bytes ● TEXT – text string; stored according to the database encoding (e.g., UTF-8) ● BLOB – data blob, typically stored as array of bytes
  • 6. SQLite Database Construction
  • 7. Sample Table 01: Book Title ID Title Author Translator ISBN Price 1 The Essential Rumi Jalal al-Din Rumi C. Barks, J. Moyne 9780062509581 17.51 2 The Illuminated Rumi Jalal al-Din Rumi C. Barks 9780767900027 25.04 3 A Year with Rumi: Daily Jalal al-Din Rumi C. Barks 9780060845971 14.92 Readings 4 A Year with Hafiz: Daily Hafiz D. Ladinsky 9780143117544 12.24 Contemplations 5 The Gift Hafiz D. Ladinsky 9780140195811 12.24 - Book Title is a Class - ID, Title, Author, Translator, ISBN, Price are Attributes - Rows 1 – 5 are Book Objects
  • 8. Sample Table 02: Book Author ID Name BirthYear DeathYear Country 1 Jalal al-Din Rumi 1207 1273 Persia 2 Hafiz 1325 1389 Persia - Book Author is a Class - ID, Name, BirthYear, DeathYear, Country, are Attributes - Row 1 is an Author Object - Row 2 is an Author Object
  • 9. Sample Table 03: Book Cover Image ISBN IMG 9780062509581 BLOB 9780767900027 BLOB 9780060845971 BLOB 9780143117544 BLOB 9780140195811 BLOB - Book Cover Image is a Class - ISBN, IMG, are Attributes - Each row is a book cover image entry mapping isbn to image blob
  • 10. Steps of SQLite DB Construction ● For each database, model each table as a Java class ● Obtain XML specifications of database tables ● For each database, design and implement a database adapter class ● Database adapters are Java classes responsible for creating, populating, querying, and maintaining databases ● Populate databases with database adapters ● Move the population databases with database adapters into background services (more on this later; we will stay in the main UI thread for now)
  • 11. Object-Oriented Data Modeling: Modeling Tables as Java Classes
  • 12. Book Title Table as BookTitle Class public class BookTitle { protected String mTitle; // title column protected String mAuthor; // author column protected String mISBN; // isbn column protected float mPrice; // price column // constructors and other methods } Source code is in of SimpleDbApp02
  • 13. Book Author Table as BookAuthor Class public class BookAuthor { protected String mName; // name column protected String mBirthYear; // birth year column protected String mDeathYear; // death year column protected float mCountry; // country column // constructors and other methods } Source code is in of SimpleDbApp02
  • 14. Book Cover Image Table as BookCoverImage Class public class BookCoverImage { protected String mISBN; // isbn column protected byte[] mCoverRef; // img column // constructors and other methods } Source code is in of SimpleDbApp02
  • 15. Obtaining XML Specifications of DB Tables
  • 16. XML DB Table Specs ● XML DB table specs can come in a variety of formats and from a variety of resources ● Basically, each table spec must describe inflatable row records; table specs inflated into table Java objects ● Table specs give you the flexibility to persist (save) Java into SQLite databases or Object databases ● Source of table specs can vary from local XML files, remote XML files, RSS feeds, etc
  • 17. XML Specs of Book Title Table <string-array name="book_title_table"> <item>The Essential Rumi;Jalal adDin Rumi;C. Barks, J. Moyne;9780062509581;17.51</item> <item>The Illuminated Rumi;Jalal adDin Rumi;C. Barks;9780767900027;25.04</item> <item>A Year with Rumi: Daily Readings;Jalal adDin Rumi;C. Barks;9780060845971;14.92</item> <item>A Year with Hafiz: Daily Contemplations;Hafiz;D. Ladinsky;9780143117544;12.24</item> <item>The Gift;Hafiz;Daniel Ladinsky;9780140195811;12.24</item> </string-array> XML source is in strings.xml of SimpleDbApp02
  • 18. XML Specs of Book Author Table <string-array name="book_author_table"> <item>Jalal adDin Rumi;1207;1273;Persia</item> <item>Hafiz;1325;1389;Persia</item> </string-array> XML source is in strings.xml of SimpleDbApp02
  • 19. XML Specs of Book Cover Image Table <string-array name="book_cover_image_table"> <item>9780062509581;essential_rumi_cover</item> <item>9780767900027;illuminated_rumi_cover</item> <item>9780060845971;year_with_rumi_cover</item> <item>9780143117544;year_with_hafiz_cover</item> <item>9780140195811;the_gift_cover</item> </string-array> XML source is in strings.xml of SimpleDbApp02
  • 20. DB XML Specs Table Inflation ● Typically there is a class that creates objects from XML table specs ● In our case, we simply inflate XML string-arrays given in strings.xml and create objects from XML strings ● Each object is then given to the database adapter (BookDbAdptr) for SQLite persistence ● Source code of the DB XML specs table inflater is in of the SimpleDbApp02 application
  • 21. Design & Implementation of Database Adapters
  • 22. DB Adapter Design & Implementation Steps ● For each DB table, publish String constants for the column names and integer constants for the column numbers ● Implement dbOpenHelper class by extending SQLiteOpenHelper ● The dbOpenHelper creates the tables and upgrades them ● If there is Java class X that models table T, DB Adapter class should have a method insertX(X x_object) ● Example: insertBookTitle(BookTitle bi) ● Source code is in BookDbAdptr.java
  • 23. References ● Source code is available here ● ●
  • 24. Feedback Bugs to vladimir dot kulyukin at gmail dot com