ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/PApp-SQL/SQL.pm
(Generate patch)

Comparing PApp-SQL/SQL.pm (file contents):
Revision 1.2 by root, Wed Nov 1 03:22:07 2000 UTC vs.
Revision 1.5 by root, Sat Jan 6 03:04:03 2001 UTC

24#use PApp::Exception; # not yet used 24#use PApp::Exception; # not yet used
25 25
26BEGIN { 26BEGIN {
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
186 die "duplicate key" 186 die "duplicate key"
187 if sql_exists "user where name = ? and pass = ?", "stefan", "geheim"; 187 if sql_exists "user where name = ? and pass = ?", "stefan", "geheim";
188 188
189=cut 189=cut
190 190
191# uncodumented, since unportable (only works with DBH even!). yet it is exported (aaargh!) 191=item $lastid = sql_insertid $sth
192
193Returns the last automatically created key value (e.g. for mysql
194AUTO_INCREMENT or sybase IDENTITY fields). It must be executed directly
195after executing the insert statement that created it.
196
197=cut
198
192sub sql_insertid { 199sub sql_insertid($) {
193 $DBH->{mysql_insertid}; 200 my $sth = shift or die "sql_insertid requires a statement handle";
201 my $dbh = $sth->{Database};
202 my $driver = $dbh->{Driver}{Name};
203
204 $driver eq "mysql" and return $sth->{mysql_insertid};
205 $driver eq "Sybase" and return sql_fetch($dbh, 'SELECT @@IDENTITY');
206 $driver eq "Informix" and return $sth->{ix_sqlerrd}[1];
207
208 die "sql_insertid does not spport the dbd driver '$driver', please see PApp::SQL::sql_insertid";
194} 209}
195 210
196=item [old-size] = cachesize [new-size] 211=item [old-size] = cachesize [new-size]
197 212
198Returns (and possibly changes) the LRU cache size used by C<sql_exec>. The 213Returns (and possibly changes) the LRU cache size used by C<sql_exec>. The

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines