Friday, 25 February 2011

Android and SQLite3

SQLite3 is the native database that comes with android. Android Debug Bridge (ADB) allow the user to execute SQLite commands on fly.

The emulator/device instances stores SQLite3 database in the folder /data/data/<package_name>/databases/.

For example, to access the database "rssitems.db" in the package, the command that can be executed in adb is the follow
1. List the devices

adb devices

2. Go to the specif shell of the device, for example the emulator

adb -s emulator-5554 shell

3. Access to the database

sqlite3 /data/ata/

It should show a prompt and a message similar to this:

SQLite version 3.5.9
Enter ".help" for instructions

Here are several commands that could be useful:

  • Check the tables of the database:

  • Get the content of a table:
Select * from TABLE_NAME;
  • Help messages:

  • Exit SQL

To exit an command:
Sometimes, when you enter a bad command, and it prompt the follow line expecting you to enter more data,
Try to type the semicolon to close the command


Normally it shows the following message:

SQL error: not an error

More information about SQLite here

No comments:

Post a Comment