Accessing SQLite with Bash, Perl and Python

Perl:
#!/usr/bin/perl -w
use DBI;
use strict;
my $db = DBI->connect("dbi:SQLite:test.db", "", "", {RaiseError => 1, AutoCommit => 1});
$db->do("CREATE TABLE n (id INTEGER PRIMARY KEY, f TEXT, l TEXT)");
$db->do("INSERT INTO n VALUES (NULL, 'john', 'smith')");
my $all = $db->selectall_arrayref("SELECT * FROM n");
foreach my $row (@$all) {
my ($id, $first, $last) = @$row;
print "$id|$first|$lastn";
}

 

Python:
#!/usr/bin/python
from pysqlite2 import dbapi2 as sqlite
db = sqlite.connect('test.db')
cur = db.cursor()
cur.execute('CREATE TABLE n (id INTEGER PRIMARY KEY, f TEXT, l TEXT)')
db.commit()
cur.execute('INSERT INTO n (id, f, l) VALUES(NULL, "john", "smith")')
db.commit()
cur.execute('SELECT * FROM n')
print cur.fetchall()

 

Bash (you need to install the sqlite3 package):
#!/bin/bash
sqlite3 test.db  "create table n (id INTEGER PRIMARY KEY,f TEXT,l TEXT);"
sqlite3 test.db  "insert into n (f,l) values ('john','smith');" 
sqlite3 test.db  "select * from n";