Using SQLite in Perl

Use library: DBD::SQLite

Contents

[edit] 1 Creating or opening a database

The file will be created if it does not exist.

This example turns autocommitting off, which speeds things up for adding large sets of data:

my $dbargs = {AutoCommit => 0,
              PrintError => 1};

my $dbh = DBI->connect("dbi:SQLite:dbname=$db_file","","",$dbargs);

[edit] 2 Creating a table

Example:

$dbh->do("CREATE TABLE alignments ( id1 varchar(30), " .
  "id2 varchar(30), length integer, score integer, pi real, " .
  "ident_positions integer, similar_positions integer, " .
  "num_gaps integer, num_gap_positions integer )");

[edit] 3 Insert values

$dbh->do("INSERT INTO alignments VALUES ( '$id1', " .
  "'$id2', $length, $score, $pi, $ident_positions, $similar_positions, " .
  "$num_gaps, $num_gap_positions )");

[edit] 4 Commit changes

$dbh->commit();

[edit] 5 Disconnect

$dbh->disconnect();
XHTML 1.1 CSS 2 Sec 508