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.8 by root, Mon Jan 22 10:53:36 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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines