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

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1741108341, '3.15.235.85', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Perl/modules/DBD/SQLite/index(114): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78