| | 79 | == SQLite == |
| | 80 | |
| | 81 | * [http://mailliststock.wordpress.com/2007/03/01/sqlite-examples-with-bash-perl-and-python/ SQLite examples with Bash, Perl and Python] |
| | 82 | {{{ |
| | 83 | #!perl |
| | 84 | #!/usr/bin/perl -w |
| | 85 | use DBI; |
| | 86 | use strict; |
| | 87 | my $db = DBI->connect("dbi:SQLite:test.db", "", "", |
| | 88 | {RaiseError => 1, AutoCommit => 1}); |
| | 89 | |
| | 90 | $db->do("CREATE TABLE n (id INTEGER PRIMARY KEY, f TEXT, l TEXT)"); |
| | 91 | $db->do("INSERT INTO n VALUES (NULL, 'john', 'smith')"); |
| | 92 | my $all = $db->selectall_arrayref("SELECT * FROM n"); |
| | 93 | |
| | 94 | foreach my $row (@$all) { |
| | 95 | my ($id, $first, $last) = @$row; |
| | 96 | print "$id|$first|$lastn"; |
| | 97 | } |
| | 98 | }}} |
| | 99 | {{{ |
| | 100 | #!python |
| | 101 | #!/usr/bin/python |
| | 102 | from pysqlite2 import dbapi2 as sqlite |
| | 103 | |
| | 104 | db = sqlite.connect('test.db') |
| | 105 | cur = db.cursor() |
| | 106 | cur.execute('CREATE TABLE n (id INTEGER PRIMARY KEY, f TEXT, l TEXT)') |
| | 107 | db.commit() |
| | 108 | cur.execute('INSERT INTO n (id, f, l) VALUES(NULL, "john", "smith")') |
| | 109 | db.commit() |
| | 110 | cur.execute('SELECT * FROM n') |
| | 111 | print cur.fetchall() |
| | 112 | }}} |
| | 113 | {{{ |
| | 114 | #!sh |
| | 115 | #!/bin/bash |
| | 116 | sqlite3 test.db "create table n (id INTEGER PRIMARY KEY,f TEXT,l TEXT);" |
| | 117 | sqlite3 test.db "insert into n (f,l) values ('john','smith');" |
| | 118 | sqlite3 test.db "select * from n"; |
| | 119 | }}} |
| | 120 | |