LA Android Unit 4
LA Android Unit 4
LA Android Unit 4
SQLLite
• Embedded RDBMS
• ACID Compliant
• Size – about 257 Kbytes
• Not a client/server architecture
• Accessed via function calls from the application
• Writing (insert, update, delete) locks the database, queries can be
done in parallel
SQLLite
• Datastore – single, cross platform file (kinda like an MS Access DB)
• Definitions
• Tables
• Indicies
• Data
Storage classes
• NULL – null value
• INTEGER - signed integer, stored in 1, 2, 3, 4, 6, or 8 bytes depending on the
magnitude of the value
• REAL - a floating point value, 8-byte IEEE floating point number.
• TEXT - text string, stored using the database encoding (UTF-8, UTF-16BE or UTF-
16LE).
• BLOB. The value is a blob of data, stored exactly as it was input.
android.database.sqlite
• Contains the SQLite database management classes that an application
would use to manage its own private database.
android.database.sqlite - Classes
• SQLiteCloseable - An object created from a SQLiteDatabase that can be closed.
• SQLiteCursor - A Cursor implementation that exposes results from a query on a
SQLiteDatabase.
• SQLiteDatabase - Exposes methods to manage a SQLite database.
• SQLiteOpenHelper - A helper class to manage database creation and version
management.
• SQLiteProgram - A base class for compiled SQLite programs.
• SQLiteQuery - A SQLite program that represents a query that reads the resulting rows
into a CursorWindow.
• SQLiteQueryBuilder - a convenience class that helps build SQL queries to be sent to
SQLiteDatabase objects.
• SQLiteStatement - A pre-compiled statement against a SQLiteDatabase that can be
reused.
android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteDatabase;
SQLiteDatabase myDatabase;
import java.util.Locale;
myDatabase.setVersion(1);
myDatabase.setLockingEnabled(true);
myDatabase.SetLocale(Locale.getDefault());
Creating Tables
myDatabase.execSQL(createAuthor);
insert( )
import android.content.ContentValues;
• http://developer.android.com/reference/android/database/package-summary.ht
ml
• Contains classes and interfaces to explore data returned through a content
provider.
• The main thing you are going to use here is the Cursor interface to get the data
from the resultset that is returned by a query
http://developer.android.com/reference/android/database/Cursor.html
Queries
• Method of SQLiteDatabase class and performs queries on the DB and returns the
results in a Cursor object
• Cursor c = mdb.query(p1,p2,p3,p4,p5,p6,p7)
• p1 ; Table name (String)
• p2 ; Columns to return (String array)
• p3 ; WHERE clause (use null for all, ?s for selection args)
• p4 ; selection arg values for ?s of WHERE clause
• p5 ; GROUP BY ( null for none) (String)
• p6 ; HAVING (null unless GROUP BY requires one) (String)
• p7 ; ORDER BY (null for default ordering)(String)
• p8 ; LIMIT (null for no limit) (String)
Simple Queries
• SQL - "SELECT * FROM ABC;"
SQLite - Cursor c = mdb.query(abc,null,null,null,null,null,null);