Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Apero's scratchpad

by Apero (Scribe)
on Sep 10, 2014 at 01:07 UTC ( [id://1100055]=scratchpad: print w/replies, xml ) Need Help??

Scratchpad ToC

To keep my scratchpad from becoming a giant mess, here's a handy table of what can be found here:




SQLite FK PRAGMA problems

(Back to ToC)

DBD::SQLite FK example. Seems to fail in recent DBD::SQLite versions (but only when AutoCommit is off.)

use strict; use warnings; use DBI; require Carp; require v5.014_000; my $dbh = DBI->connect( "dbi:SQLite:db=:memory:", "", "", { AutoCommit => 0, RaiseError => 1, PrintError => 0, } ); defined $dbh or die "No dbh: failed database setup!"; printf( "SQLite DBD version: %s (%s)\n", $dbh->{sqlite_version}, $DBD::SQLite::VERSION ); # SQLite FK boilerplate setup follows. # Here the PRAGMA is called to enable foreign_keys. # However, PRAGMA will work on unknown/unsupported values. # Thus we have to check that it actually got set if we care. # With RaiseError, encapsulate DB work in eval: eval { # Attempt to enable FK support: $dbh->do( 'PRAGMA foreign_keys(1)' ); # Now query the actual value: my $fk_row = $dbh->selectrow_arrayref( 'PRAGMA foreign_keys' ); defined $fk_row or die "FK verify query failed. Should not happen. +"; # And verify FK support is now enabled: die "SQLite FK support is still disabled!" unless ($fk_row->[0] == + 1); # Indicate success if we got here, and disconnect to be nice. print "Success: FK support was enabled as intended.\n"; $dbh->disconnect; }; # Handle errors from DB work above: (safe as of Perl >=5.14.0.) if ($@) { my $err = $@; # attempt rollback, avoids needless warnings: eval { $dbh->rollback }; # report the error and a backtrace: Carp::confess( "DB work error: $err" ); }
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2024-03-29 11:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found