Snippets

Philippe Casgrain Bash script to create and populate an SQLite database

Created by Philippe Casgrain
#!/bin/bash

DATABASE="daylight-tests.sqlite"

if [ -e "$DATABASE" ]
then
    echo "$DATABASE exists, nothing to do"
    exit 0
fi

echo "Creating $DATABASE"

sqlite3 "$DATABASE" <<!
CREATE TABLE locations(location_id integer PRIMARY KEY, name text NOT NULL, timezone text NOT NULL, sort_order integer UNIQUE);
INSERT INTO locations(name, timezone, sort_order) VALUES('Aylmer', 'America/Montreal', 1);
INSERT INTO locations(name, timezone, sort_order) VALUES('Montréal', 'America/Montreal', 2);
INSERT INTO locations(name, timezone, sort_order) VALUES('Toronto', 'America/Toronto', 3);
INSERT INTO locations(name, timezone, sort_order) VALUES('San Francisco', 'America/Los_Angeles', 4);
!

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.