Search notes:

Perl module DBD::SQLite

#!/usr/bin/perl
use warnings;
use strict;

use DBI;

my $dbh = DBI->connect('dbi:SQLite:dbname=the.db') or die "Could not create the.db";

#
#   Check, if table already exists:
#
my ($table_exists) = $dbh->selectrow_array ("select 1 from sqlite_master where type='table' and name='foo'");
if ($table_exists) {
  print "Table foo already exists\n";
}
else {
  print "Creating table foo\n";
  $dbh -> do ('create table foo (col_1 number, col_2 varchar)');
}


$dbh -> begin_work;

# Inserting values
# ----------------

my $sth = $dbh -> prepare('insert into foo values (:v1, :v2)');

$sth -> execute(1, 'one');
$sth -> execute(2, 'two');
$sth -> execute(3, 'three');
$sth -> execute(4, 'four');
$sth -> execute(5, 'five');

# Selecting values
# ----------------

$sth = $dbh -> prepare('select * from foo where col_1 > :v1 and col_2 like :v2');
$sth -> execute(1, '%o%');

while (my @r = $sth -> fetchrow_array) {
  printf ("%2d %s\n", @r);
}

$dbh -> commit;

$dbh -> disconnect;
Github repository PerlModules, path: /DBD/SQLite/script.pl

See also

DBD::SQLite - testing AutoCommit
DBD::SQLite - Using utf8
DBD::SQLite - determine SQLite version
DBD::SQLite - handling nulls
Inserts in select loop (Trying to demonstrate how readers don't block writers and vice versa).
DBD::SQLite - Explaining a query plan
$dbh->sqlite_create_function
$dbh->sqlite_last_insert_rowid
regexp: searching with regular expressions.
Perl modules.
SQLite

Index