Search notes:

Perl module DBD::SQLite - testing AutoCommit

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

use Getopt::Long;
use DBI;

my $db = 'AutoCommit.db';

Getopt::Long::GetOptions(
    "new-db"               => \my $new_db,
    "autocommit"           => \my $autocommit,
    "no-autocommit"        => \my $no_autocommit,
    "commit-when-finished" => \my $commit_when_finished,
) or die;

unless (-e $db) {
  $new_db = 1;
}

if ($new_db) {
  if (-e $db) {
    unlink $db or die;
  }
}

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

if ($new_db) {
  $dbh -> do('create table t (v)') or die;
}
else {

  print "Values found in table\n  ";
  my @v = @{$dbh->selectall_arrayref('select v from t')};

  print join "\n  ", map {$_->[0]} @v;

}

if ($autocommit) {
  $dbh->{AutoCommit} = 1;
}
if ($no_autocommit) {
  $dbh->{AutoCommit} = 0;
}


my $sth = $dbh -> prepare('insert into t values (?)');

for (@ARGV) {
  $sth -> execute($_)
}


if ($commit_when_finished) {
  $sth -> commit;
}
Github repository PerlModules, path: /DBD/SQLite/AutoCommit.pl

See also

DBD::SQLite, 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...', 1758204644, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Perl/modules/DBD/SQLite/AutoCommit(98): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78