Guest User

Untitled

a guest
Aug 23rd, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. #Modified script
  2. #!/usr/bin/perl -w
  3.  
  4. use strict;
  5. use lib q(/home/vincent/tmp);
  6. use MyApp::SQLite;
  7. use Data::Dumper;
  8.  
  9.  
  10. my $dbfile = shift || die "Usage: $0 db_file\n";
  11.  
  12. my $dbh = MyApp::SQLite->connect(
  13. "dbi:SQLite:dbname=$dbfile", '', '',
  14. {
  15. RaiseError => 1,
  16. PrintError => 0,
  17. }
  18. );
  19.  
  20. END {
  21. $dbh->do('DROP TABLE try');
  22. $dbh->disconnect;
  23. }
  24.  
  25. $dbh->do('CREATE TABLE try (a TEXT)');
  26.  
  27. my $ins = $dbh->prepare('INSERT INTO try (a) VALUES (?)');
  28. for my $val (qw(foo bar bat woo oop craw)) {
  29. $ins->execute($val);
  30. }
  31.  
  32. my $sel = 'select * from try limit 1' ;
  33.  
  34. for my $test( 1.. 3) {
  35.  
  36. my $cached_dbh = MyApp::SQLite->connect_cached(
  37. "dbi:SQLite:dbname=$dbfile", '', '',
  38. {
  39. RaiseError => 1,
  40. PrintError => 0,
  41.  
  42. Callbacks => {
  43. "connect_cached.reused" => sub {
  44. print "reused!!!";
  45. return ;
  46. },
  47.  
  48. }
  49.  
  50. }
  51. );
  52.  
  53. print "select $test\n";
  54. print join "\n " =>
  55. Dumper($cached_dbh->selectall_arrayref($sel));
  56. print "\n\n";
  57.  
  58. print Dumper( $cached_dbh->{Driver}->{CachedKids} );
  59.  
  60. }
  61.  
  62. ################
  63. #output
  64. ################
  65.  
  66. select 1
  67. $VAR1 = [
  68. [
  69. 'foo'
  70. ]
  71. ];
  72.  
  73.  
  74. $VAR1 = {
  75. 'dbname=bla!!!AutoCommit=\'1\',Callbacks=\'HASH(0x217a520)\',PrintError=\'0\',RaiseError=\'1\',Username=\'\',dbi_connect_method=\'connect_cached\'' => bless( {}, 'MyApp::SQLite::db' )
  76. };
  77. select 2
  78. $VAR1 = [
  79. [
  80. 'foo'
  81. ]
  82. ];
  83.  
  84.  
  85. $VAR1 = {
  86. 'dbname=bla!!!AutoCommit=\'1\',Callbacks=\'HASH(0x217a550)\',PrintError=\'0\',RaiseError=\'1\',Username=\'\',dbi_connect_method=\'connect_cached\'' => bless( {}, 'MyApp::SQLite::db' ),
  87. 'dbname=bla!!!AutoCommit=\'1\',Callbacks=\'HASH(0x217a520)\',PrintError=\'0\',RaiseError=\'1\',Username=\'\',dbi_connect_method=\'connect_cached\'' => bless( {}, 'MyApp::SQLite::db' )
  88. };
  89. select 3
  90. $VAR1 = [
  91. [
  92. 'foo'
  93. ]
  94. ];
  95.  
  96.  
  97. $VAR1 = {
  98. 'dbname=bla!!!AutoCommit=\'1\',Callbacks=\'HASH(0x217a550)\',PrintError=\'0\',RaiseError=\'1\',Username=\'\',dbi_connect_method=\'connect_cached\'' => bless( {}, 'MyApp::SQLite::db' ),
  99. 'dbname=bla!!!AutoCommit=\'1\',Callbacks=\'HASH(0x217a520)\',PrintError=\'0\',RaiseError=\'1\',Username=\'\',dbi_connect_method=\'connect_cached\'' => bless( {}, 'MyApp::SQLite::db' ),
  100. 'dbname=bla!!!AutoCommit=\'1\',Callbacks=\'HASH(0x217a5b0)\',PrintError=\'0\',RaiseError=\'1\',Username=\'\',dbi_connect_method=\'connect_cached\'' => bless( {}, 'MyApp::SQLite::db' )
  101. };
Advertisement
Add Comment
Please, Sign In to add comment