Listing 139 Interacting with a sqlite database

/data/ch13 A

sqlite3 daytime_db.db

SQLite version 3 . 5 . o Enter ".help" for instructions sqlite> .databases .databases seq name file

Connect to our database file

0 main /data/ch13/daytime_db.db sqlite> .tables

.tables hits sqlite> .schema hits .schema hits

CREATE TABLE hits (hittime date,hittext text); sqlite> .header on .header on sqlite> .mode column .mode column sqlite> select * from hits; <1—E Select rows select * from hits; hittime hittext

Q Examine database structure

<—Q The Create statement

2oo8-o7-29 o7: 31 : 35 2oo8-o7-29 o7: 56:27 2oo8-o7-29 o7: 56:28 2oo8-o7-29 o7: 56:29 2oo8-o7-29 o7: 56 :3o sqlite> .exit

Tue Jul 29 o7 : 31 : 35 2oo8 Tue Jul 29 o7 : 56 : 27 2oo8 Tue Jul 29 o7 : 56 : 28 2oo8 Tue Jul 29 o7 : 56 : 28 2oo8 Tue Jul 29 o7 : 56 : 3 o 2oo8

The SQLite database operates in a similar fashion to other, modern SQL-based environments. In listing 13.9 we see the output from an interactive session where the database for this chapter's sample application is opened O. A series of commands given at the sqlite> prompt Q display the contents of the database in terms of structure. The schema command dumps the Data Definition Language for a particular table. In this case, we see the CREATE TABLE instructions for the hits table ©. Viewing the data is simple with the use of the familiar select statement ©.

The SQLite database engine is known for its simplicity. This section displayed a simple interaction and just how easy it is to employ. In addition, the SQLite3 database may be pulled from the Android Emulator and used on the development machine, as shown in figure 13.8.

t\ C:\WINOOWS\tystem32\cmd.eite

-5-4>g"\tQoIs\adb pull /dat JavL iH_db ilb -1 enpMU*y 1. ui'.'_tlb tHi

128 KB/s (0 bytes in 2048.000s>

C:Ssuf twaile\s(ilite-3 .5 .4>&qlite3 \tenpSdaytine_db_db

SQLite uersion 3.5.4

Enter "'.help" Fer instructions scilitc> .databases

0 nain C:\tenjp\daiitirte_db.dlj

G£(lite> .tables hits scilite> select * from hits; 2008-87-29 07;31:35ITue Jul 29 07:31:35 2008 aHBS-007=56=2?!Tue Jul 29 07=56:27 2008 2008-07-29 07:56:28ITue Jul 29 07:56:28 2008 2008-07-29 07:56 : 29 ! Tue Jul 29 07:56:28 2008 2008-07-29 07:56:29 ! lue Jul 29 07:56:29 2008 2008-07-29 07:56:29ITue Jul 29 07:56:29 2008 S0H8-07-29 07:56:29ITue Jul 29 HV:S6:29 2W08 2008-07-29 07:56:29ITue Jul 29 07:56:29 2008 2008-07-29 07:56: 30ITue Jul 29 07:56=30 2008 sqlite) -exit hits ;

9 Jul 29 07:5 c Jul 29 07:5 a Jul 29 07:5 ; Jul 39 07:5 s Jul 29 07:5 s Jul 29 07=5

C:\sof tuareSsiylite-3 .5

Figure 13.8 The SQLite database on the development machine

This feature makes Android a very compelling platform for mobile data collection applications because synching data can be as simple as copying a database file that is compatible across multiple platforms.

0 0

Post a comment