Introducing SQLite

SQLite1 is a tiny yet powerful database engine created by Dr. Richard Hipp in 2000. It is arguably the most widely deployed SQL database engine in the world. Besides Android, SQLite can be found in the Apple iPhone, Symbian phones, Mozilla Firefox, Skype, PHP, Adobe AIR, Mac OS X, Solaris, and many other places.


The SQLite source code contains no license because it is in the public domain. Instead of a license, the source offers you this blessing:

May you do good and not evil.

May you find forgiveness for yourself and forgive others.

May you share freely, never taking more than you give.

There are three reasons why it is so popular:

• It's free. The authors have placed it in the public domain and don't charge for its use.

• It's small. The current version is about 150KB, well within the memory budget of an Android phone.

• It requires no setup or administration. There is no server, no config file, and no need for a database administrator.

A SQLite database is just a file. You can take that file, move it around, and even copy it to another system (for example, from your phone to your workstation), and it will work fine. Android stores the file in the /data/data/packagename/databases directory (see Figure 9.1, on the next page). You can use the adb command or the File Explorer view in Eclipse (Window > Show View > Other... > Android > File Explorer) to view, move, or delete it.

Instead of calling Java I/O routines to access this file from your program, you run Structured Query Language (SQL) statements. Through its helper classes and convenience methods, Android hides some of the syntax from you, but you still need to know a bit of SQL to use it.

9.2 SQL 101

If you've used Oracle, SQL Server, MySQL, DB2, or other database engines, then SQL should be old hat to you. You can skip this section and go to Section 9.3, Hello, Database, on page 181. For the rest of you, here's a quick refresher.







Permissions Info

■ J org, exam pie, events j {¿p databases

2010-06-02 2010-06-08 2010-06-08

00:12 02:10 02:11

drwxr-x--x drwxr-x--x drwxrwx--x

L=] events,db





■ org.example.wallpaper

■ Q^ org.example.widget

2010-06-08 2010-06-02 2010-06-08 2010-06-08

02:10 00:23 01:50 01:57

drwxr-xi-x drwxr-x--K drwxr-x--x drwxr-x--x

Figure 9.1: SQLite stores an entire database in one file.

To use a SQL database, you submit SQL statements and get back results. There are three main types of SQL statements: DDL, Modification, and Query.

0 0

Post a comment