Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Modified script
- #!/usr/bin/perl -w
- use strict;
- use lib q(/home/vincent/tmp);
- use MyApp::SQLite;
- use Data::Dumper;
- my $dbfile = shift || die "Usage: $0 db_file\n";
- my $dbh = MyApp::SQLite->connect(
- "dbi:SQLite:dbname=$dbfile", '', '',
- {
- RaiseError => 1,
- PrintError => 0,
- }
- );
- END {
- $dbh->do('DROP TABLE try');
- $dbh->disconnect;
- }
- $dbh->do('CREATE TABLE try (a TEXT)');
- my $ins = $dbh->prepare('INSERT INTO try (a) VALUES (?)');
- for my $val (qw(foo bar bat woo oop craw)) {
- $ins->execute($val);
- }
- my $sel = 'select * from try limit 1' ;
- for my $test( 1.. 3) {
- my $cached_dbh = MyApp::SQLite->connect_cached(
- "dbi:SQLite:dbname=$dbfile", '', '',
- {
- RaiseError => 1,
- PrintError => 0,
- Callbacks => {
- "connect_cached.reused" => sub {
- print "reused!!!";
- return ;
- },
- }
- }
- );
- print "select $test\n";
- print join "\n " =>
- Dumper($cached_dbh->selectall_arrayref($sel));
- print "\n\n";
- print Dumper( $cached_dbh->{Driver}->{CachedKids} );
- }
- ################
- #output
- ################
- select 1
- $VAR1 = [
- [
- 'foo'
- ]
- ];
- $VAR1 = {
- 'dbname=bla!!!AutoCommit=\'1\',Callbacks=\'HASH(0x217a520)\',PrintError=\'0\',RaiseError=\'1\',Username=\'\',dbi_connect_method=\'connect_cached\'' => bless( {}, 'MyApp::SQLite::db' )
- };
- select 2
- $VAR1 = [
- [
- 'foo'
- ]
- ];
- $VAR1 = {
- 'dbname=bla!!!AutoCommit=\'1\',Callbacks=\'HASH(0x217a550)\',PrintError=\'0\',RaiseError=\'1\',Username=\'\',dbi_connect_method=\'connect_cached\'' => bless( {}, 'MyApp::SQLite::db' ),
- 'dbname=bla!!!AutoCommit=\'1\',Callbacks=\'HASH(0x217a520)\',PrintError=\'0\',RaiseError=\'1\',Username=\'\',dbi_connect_method=\'connect_cached\'' => bless( {}, 'MyApp::SQLite::db' )
- };
- select 3
- $VAR1 = [
- [
- 'foo'
- ]
- ];
- $VAR1 = {
- 'dbname=bla!!!AutoCommit=\'1\',Callbacks=\'HASH(0x217a550)\',PrintError=\'0\',RaiseError=\'1\',Username=\'\',dbi_connect_method=\'connect_cached\'' => bless( {}, 'MyApp::SQLite::db' ),
- 'dbname=bla!!!AutoCommit=\'1\',Callbacks=\'HASH(0x217a520)\',PrintError=\'0\',RaiseError=\'1\',Username=\'\',dbi_connect_method=\'connect_cached\'' => bless( {}, 'MyApp::SQLite::db' ),
- 'dbname=bla!!!AutoCommit=\'1\',Callbacks=\'HASH(0x217a5b0)\',PrintError=\'0\',RaiseError=\'1\',Username=\'\',dbi_connect_method=\'connect_cached\'' => bless( {}, 'MyApp::SQLite::db' )
- };
Advertisement
Add Comment
Please, Sign In to add comment