• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Mobile Application Development: Lecture 14
 

Mobile Application Development: Lecture 14

on

  • 584 views

 

Statistics

Views

Total Views
584
Views on SlideShare
325
Embed Views
259

Actions

Likes
0
Downloads
0
Comments
0

23 Embeds 259

http://vkedco.blogspot.com 124
http://www.vkedco.blogspot.com 63
http://vkedco.blogspot.in 27
http://vkedco.blogspot.com.br 5
http://vkedco.blogspot.com.es 5
http://vkedco.blogspot.co.uk 5
http://vkedco.blogspot.de 4
http://vkedco.blogspot.mx 3
http://vkedco.blogspot.co.il 3
http://www.blogger.com 3
http://vkedco.blogspot.fr 2
http://vkedco.blogspot.pt 2
http://www.vkedco.blogspot.co.il 2
http://vkedco.blogspot.no 2
http://vkedco.blogspot.fi 1
http://vkedco.blogspot.ie 1
http://www.vkedco.blogspot.in 1
http://www.vkedco.blogspot.ca 1
http://vkedco.blogspot.ro 1
http://vkedco.blogspot.ca 1
http://www.vkedco.blogspot.ro 1
http://vkedco.blogspot.cz 1
http://vkedco.blogspot.tw 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Mobile Application Development: Lecture 14 Mobile Application Development: Lecture 14 Presentation Transcript

    • Mobile Application Development Lecture 14 Vladimir Kulyukin Department of Computer Science Utah State Universityhttp://www.youtube.com/vkedco www.vkedco.blogspot.com
    • Outline ● Persisting Structured Data in SQL Databases ● Lite Intro to SQLite ● SQLite Database Inspection ● SQLite by Examplehttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Persisting Structured Data in SQL Databaseshttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • SharedPreferences: Pros & Cons ● Pros – Lightweight – Easy to code and debug ● Cons – Slow with large data volumes – Not helpful with highly structured data when key/value pairs are not sufficient – Entire file needs to be read and parsed to access data – Takes up more space because XML is used for storagehttp://www.youtube.com/vkedco www.vkedco.blogspot.com
    • SQL Databases: Pros & Cons ● Pros – Flexible with structured data – Scalable: can handle large data volumes – Robust: can handle incremental changes – Responsive: can handle flexible queries ● Cons – Heavyweight: more code & more memory – Maintenance: Harder to code & debughttp://www.youtube.com/vkedco www.vkedco.blogspot.com
    • Database Design ● Standard database design practices apply on Android ● A key design principle is to manage space well: reduction redundancy via database normalization ● The objective of database normalization is to decompose relations with anomalies to produce smaller, well structured relations ● Database design is more of an art than a science: takes experience & practice ● Helpful resource: en.wikipedia.org/Database_normalizationhttp://www.youtube.com/vkedco www.vkedco.blogspot.com
    • Database Fundamentals ● Database is a persistent collection of structured data ● Data are structured because they are organized in tables ● A Table is similar to an Excel spreadsheet except that its columns have standard SQL data types (e.g., TEXT, INTEGER, FLOAT, etc.) ● In terms of Object-Oriented Modeling, each table represents an Class (e.g., Book, Author) and each column represents an Attribute ● Each table row represents an Object of a specific Classhttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Sample Table 01: Book 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 is a Class - ID, Title, Author, Translator, ISBN, Price are Attributes - Rows 1 – 5 are Book Objectshttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Sample Table 02: Author ID Name BirthYear DeathYear Country 1 Jalal al-Din Rumi 1207 1273 Persia 2 Hafiz 1325 1389 Persia - Author is a Class - ID, Name, BirthYear, DeathYear, Country, are Attributes - Row 1 is an Author Object - Row 2 is an Author Objecthttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • The ID Column ● In many tables, the ID column represents the primary key ● The primary key is the key that uniquely identifies the row entry object ● When design an SQL table, it is typical (not necessary!) to specify the primary key as an integer and mark it as auto-incrementable: this way every inserted row is guaranteed to have a unique primary keyhttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Lite Intro to SQLitehttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • SQLite on Android ● Android offers SQLite relational database library ● Every application can create its own database over which it has complete control ● SQLite databases should be considered only when you need to manage complex, structured data ● Databases are stored in /data/data/<package_name>/databases/ ● Example: /data/data/org.vkedco.mobappdev.simple_db_app_01/databases/http://www.youtube.com/vkedco www.vkedco.blogspot.com
    • What is SQLite? ● SQLite is a relational database management system (RDBMS) ● SQLite is a compact C library that is part of the Android software stack ● Since it is a library, it can be integrated into each application without external dependencies: this simplifies transactions and synchronizations, minimizes latencyhttp://www.youtube.com/vkedco www.vkedco.blogspot.com
    • Command Line DB Access ● Suppose that you have created a database (we will learn how to do this later) and want to interact with it 1. Open a command line 2. CD into platform-tools directory 3. Connect to the device (e.g., adb -e shell) 4. CD into the database directory: cd /data/data/<package>databases> 5. Execute: sqlite3 <database_name> (e.g. sqlite3 book_info.db) Now you can interct with book_info.db via sqlite shell 6. Execute .quit to quithttp://www.youtube.com/vkedco www.vkedco.blogspot.com
    • Discovering TABLE Schemas ● A Table Schema is the specification of column values and types for a given table ● To access table schemas for a DB: 1. Get in to the sqlite shell 2. Execute: .schema You should see something like: CREATE TABLE android_metadata (locale TEXT); CREATE TABLE author (ID integer primary key autoincrement, Name text not null, ...); CREATE TABLE book (ID integer primary key autoincrement, Title text not null, ...);http://www.youtube.com/vkedco www.vkedco.blogspot.com
    • SQLite by Examplehttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Displaying Tables ● To display the entire table: SELECT * FROM <TABLE>; Examples: – SELECT * FROM BOOK; – SELECT * FROM AUTHOR;http://www.youtube.com/vkedco www.vkedco.blogspot.com
    • Project Columns ● To project the values of specific columns for each record: SELECT COLUM_NAME_1, …, COLUMN_NAME_n FROM <TABLE>; Examples: – SELECT Author, Title FROM BOOK; – SELECT Title, Author FROM BOOK;http://www.youtube.com/vkedco www.vkedco.blogspot.com
    • Record Retrieval ● To retrieve records with specific values, use the WHERE clause: SELECT COLUM_NAME_1, …, COLUMN_NAME_n FROM <TABLE> WHERE <COL_VAL_SPEC>; Examples: – SELECT Title FROM BOOK WHERE ID = 3; – SELECT Title, Author FROM BOOK WHERE ID < 3;http://www.youtube.com/vkedco www.vkedco.blogspot.com
    • Record Ordering ● To order records by attributes, use the ORDER BY clause: SELECT COLUM_NAME_1, …, COLUMN_NAME_n FROM <TABLE> ORDER BY COL_NAME Asc/Desc; Examples: – SELECT Title, Author FROM BOOK ORDER BY Price Asc; – SELECT Title, Author FROM BOOK ORDER BY Price Desc;http://www.youtube.com/vkedco www.vkedco.blogspot.com
    • References ● en.wikipedia.org/Database_normalization ● http://developer.android.com/tools/help/adb.html ● http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.htmlhttp://www.youtube.com/vkedco www.vkedco.blogspot.com
    • Feedback Bugs to vladimir dot kulyukin at gmail dot comhttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com