… | |
… | |
24 | #use PApp::Exception; # not yet used |
24 | #use PApp::Exception; # not yet used |
25 | |
25 | |
26 | BEGIN { |
26 | BEGIN { |
27 | use base Exporter; |
27 | use base Exporter; |
28 | |
28 | |
29 | $VERSION = 0.1; |
29 | $VERSION = 0.11; |
30 | @EXPORT = qw( |
30 | @EXPORT = qw( |
31 | sql_exec sql_fetch sql_fetchall sql_exists sql_insertid $sql_exec |
31 | sql_exec sql_fetch sql_fetchall sql_exists sql_insertid $sql_exec |
32 | ); |
32 | ); |
33 | @EXPORT_OK = qw( |
33 | @EXPORT_OK = qw( |
34 | connect_cached |
34 | connect_cached |
… | |
… | |
73 | my ($id, $dsn, $user, $pass, $flags, $connect) = @_; |
73 | my ($id, $dsn, $user, $pass, $flags, $connect) = @_; |
74 | # the following line is duplicated in PApp::SQL::Database::new |
74 | # the following line is duplicated in PApp::SQL::Database::new |
75 | $id = "$id\0$dsn\0$user\0$pass"; |
75 | $id = "$id\0$dsn\0$user\0$pass"; |
76 | unless ($dbcache{$id} && $dbcache{$id}->ping) { |
76 | unless ($dbcache{$id} && $dbcache{$id}->ping) { |
77 | #warn "connecting to ($dsn|$user|$pass|$flags)\n";#d# |
77 | #warn "connecting to ($dsn|$user|$pass|$flags)\n";#d# |
78 | # first, nuke our cache (sooory ;) |
78 | # first, nuke our statement cache (sooory ;) |
79 | cachesize cachesize 0; |
79 | cachesize cachesize 0; |
80 | # then connect anew |
80 | # then connect anew |
81 | $dbcache{$id} = |
81 | $dbcache{$id} = |
82 | eval { DBI->connect($dsn, $user, $pass, $flags) } |
82 | eval { DBI->connect($dsn, $user, $pass, $flags) } |
83 | || eval { DBI->connect($dsn, $user, $pass, $flags) } |
83 | || eval { DBI->connect($dsn, $user, $pass, $flags) } |
84 | || die "$DBI::errstr\n"; |
84 | || die "unable to connect to database $dsn: $DBI::errstr\n"; |
85 | $connect->($dbcache{$id}) if $connect; |
85 | $connect->($dbcache{$id}) if $connect; |
86 | } |
86 | } |
87 | $dbcache{$id}; |
87 | $dbcache{$id}; |
88 | } |
88 | } |
89 | |
89 | |