Home > Uncategorized > Connect to sqlite3 databases and make queries

Connect to sqlite3 databases and make queries

Problem
You have a binary sqlite3 database file and you want to make some queries on it: find out what tables it has, look at the content of the tables, etc.

Solution
There is a command called “sqlite3” which is a client for sqlite3 databases. Let’s say our database is stored in a file called “database.sqlite“. (Here “.sqlite” is the file extension.)

# open database.sqlite with the client:
sqlite3 database.sqlite
# let's get the list of tables in this database:
.tables
# Say it has a table called "images". Let's see its content:
select * from images;

To learn more about the commands, just type “.help” in the client. You can dump a database in SQL text format, you can get the schema of a table, etc.

Tip
Although .sqlite database files are binary files, you can open them with a text editor too. At the top you can see the schemas of the tables in text format. Just be careful not to modify it.

Create a database from a schema (update 20111120)

sqlite3 database.sqlite < schema.sql
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: