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.7 by root, Mon Jan 15 00:19:55 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;
310 321
311=cut 322=cut
312 323
313sub dsn($) { 324sub dsn($) {
314 my $self = shift; 325 my $self = shift;
315 $self->[1][1]; 326 (split /\x00/, $self->[0])[1];
316} 327}
317 328
318=back 329=back
319 330
320=cut 331=cut

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines