Installing SQLite on Raspberry Pi

SQLite is an embedded SQL database engine that provides a lightweight disk-based database.  It doesn’t require a separate server process and allows accessing data using SQL query language.

We use SQLite database as a buffer or distribution center  where all the data from the CAN-Bus network is going to and all other applications read the data when required and act on it.

Installation process is fairly simple and uneventful.

Login to your Raspberry Pi via ssh terminal (Putty)

Update and upgrade Raspberry Pi packages –

sudo apt-get update
sudo apt-get upgrade

Although it is not usually required, I’d recommend to restart your Raspberry Pi

sudo reboot

Install SQLite3  –

sudo apt-get install sqlite3

That  is it.

The SQLite is installed and ready for use.

Here is a few simple commands to play with SQLite:

Start SQLite interface by opening a DB file:

pi@raspberrypi:~ $ sqlite3 Test_DB
SQLite version 3.16.2 2017-01-06 16:32:41
Enter ".help" for usage hints.
sqlite>

Create a table

sqlite> create table MyPhoneBook (Person_ID integer, First_Name text, Last_Name text, Phone text);
sqlite>

Insert some data into the table

sqlite> insert into MyPhoneBook (Person_ID, First_Name, Last_Name, Phone) values (1,"James", "Bond", "+7(495)1234567");
sqlite> insert into MyPhoneBook (Person_ID, First_Name, Last_Name, Phone) values (2,"Mata", "Hari", "+33123456789");
sqlite>

Read data from the table

sqlite> select * from MyPhoneBook;

To exit SQLite press Ctrl-D