The SQLite database

This application employs a simple database structure created with the sqlite3 application. We interact with sqlite3 from the adb shell environment, as shown in figure 13.7.

|H 1. WINDOWS S-.VI-- il',/ . 111 I cmi' - adb v'it'll

It II

tt iqlite3 daytime..db.dh

sqlite3 daijtime_db.db

SQLite version 3.5,0

¡Enter ".help" for instructions

5£flite> .databases

.databases

seq name file

[0 nain /data/chl3/daytir>e_db.db

sqlite> -tables

.tables

hits

sqlite> .schema hits

. schena hits

ICREOTH TÛRT.F bits (hittime data.

ihittext text);

sqlite> .header on

-header on

sqlite> .node column

-node column

sqlitey select » from hits;

select * from hits;

Kiittins bittcxt

2B08-B7-29 07:31:35 Tue Jul

07:31:35 2008

2008-07-29 07:56:27 Tue Jul

29

07:S6:27 2008

2008-07-29 07:56:28 Tue Jul

29

07:56:28 2008

2008 -07 29 07:56:29 Tue Jul

2?

0?T56:28 2008

2008-07-29 07:56:29 Tue Jul

29

07:56:29 2 008

2008 07-29 07-56-29 Tue Jul

2 V

07:56:29 2008

2UM8-U7-29 07:56:29 Tue Jul

29

07:56:29 2BB8

2008-07-29 07:56:29 Tue Jul

29

07:56:29 2008

2008-07-29 07:56:30 Tue Jul

29

07:56:30 2008

sqlite> -exit

.exit a

Figure 13.7 Sqlite3 from the command line in the adb shell

Figure 13.7 Sqlite3 from the command line in the adb shell

The purpose of this database is to record some data each time Daytime Server processes an incoming request. From a data perspective this sample is a bit boring as it simply records the system time plus the text returned to the client, which is a ctime formatted time string. Though somewhat redundant from a data perspective, the purpose is to demonstrate the use of SQLite from our C application, utilizing the Android/Linux resident sqlite3 library, libsqlite.so.

The previous section of code outlined the syntax for inserting a row into the database; this section shows how to interact with the database using the sqlite3 tool. The sequence shown in figure 13.7 is broken out and explained in listing 13.9.

0 0

Post a comment