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.6 by root, Sun Jan 7 02:53:53 2001 UTC vs.
Revision 1.9 by root, Sat Feb 3 17:48:02 2001 UTC

195 195
196=cut 196=cut
197 197
198=item $lastid = sql_insertid $sth 198=item $lastid = sql_insertid $sth
199 199
200Returns the last automatically created key value (e.g. for mysql 200Returns the last automatically created key value. It must be executed
201AUTO_INCREMENT or sybase IDENTITY fields). It must be executed directly
202after executing the insert statement that created it. 201directly after executing the insert statement that created it. This is
202what is actually returned for various databases. If your database is
203missing, please send me an e-mail on how to implement this ;)
204
205 mysql: first C<AUTO_INCREMENT> column set to NULL
206 postgres: C<oid> column (is there a way to get the last SERIAL?)
207 sybase: C<IDENTITY> column of the last insert (slow)
208 informix: C<SERIAL> or C<SERIAL8> column of the last insert
209
210Except for sybase, this does not require a server access.
203 211
204=cut 212=cut
205 213
206sub sql_insertid($) { 214sub sql_insertid($) {
207 my $sth = shift or die "sql_insertid requires a statement handle"; 215 my $sth = shift or die "sql_insertid requires a statement handle";
208 my $dbh = $sth->{Database}; 216 my $dbh = $sth->{Database};
209 my $driver = $dbh->{Driver}{Name}; 217 my $driver = $dbh->{Driver}{Name};
210 218
211 $driver eq "mysql" and return $sth->{mysql_insertid}; 219 $driver eq "mysql" and return $sth->{mysql_insertid};
220 $driver eq "Pg" and return $sth->{pg_oid_status};
212 $driver eq "Sybase" and return sql_fetch($dbh, 'SELECT @@IDENTITY'); 221 $driver eq "Sybase" and return sql_fetch($dbh, 'SELECT @@IDENTITY');
213 $driver eq "Informix" and return $sth->{ix_sqlerrd}[1]; 222 $driver eq "Informix" and return $sth->{ix_sqlerrd}[1];
214 223
215 die "sql_insertid does not spport the dbd driver '$driver', please see PApp::SQL::sql_insertid"; 224 die "sql_insertid does not spport the dbd driver '$driver', please see PApp::SQL::sql_insertid";
216} 225}
217 226
232 241
233=cut 242=cut
234 243
235=item reinitialize [not exported] 244=item reinitialize [not exported]
236 245
237Clears any internal caches (statement cache, database handle cache). 246Clears any internal caches (statement cache, database handle
247cache). Should be called after C<fork> and other accidents that invalidate
248database handles.
238 249
239=cut 250=cut
240 251
241sub reinitialize { 252sub reinitialize {
242 cachesize cachesize 0; 253 cachesize cachesize 0;
248 259
249=back 260=back
250 261
251=cut 262=cut
252 263
264reinitialize;
265
253package PApp::SQL::Database; 266package PApp::SQL::Database;
254 267
255=head2 THE DATABASE CLASS 268=head2 THE DATABASE CLASS
256 269
257Again (sigh) the problem of persistency. What do you do when you have to serialize on object 270Again (sigh) the problem of persistency. What do you do when you have to serialize on object
308 321
309=cut 322=cut
310 323
311sub dsn($) { 324sub dsn($) {
312 my $self = shift; 325 my $self = shift;
313 $self->[1][1]; 326 (split /\x00/, $self->[0])[1];
314} 327}
315 328
316=back 329=back
317 330
318=cut 331=cut
319
320reinitialize;
321 332
3221; 3331;
323 334
324=head1 BUGS 335=head1 BUGS
325 336

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines