1 package DBIx::Class::Storage::DBI::ODBC::Microsoft_SQL_Server;
5 use base qw/DBIx::Class::Storage::DBI::MSSQL/;
7 sub _prep_for_execute {
9 my ($op, $extra_bind, $ident, $args) = @_;
11 my ($sql, $bind) = $self->next::method (@_);
12 $sql .= ';SELECT SCOPE_IDENTITY()' if $op eq 'insert';
21 my ($rv, $sth, @bind) = $self->dbh_do($self->can('_dbh_execute'), @_);
22 if ($op eq 'insert') {
23 $self->{_scope_identity} = $sth->fetchrow_array;
27 return wantarray ? ($rv, $sth, @bind) : $rv;
30 sub last_insert_id { shift->{_scope_identity} }
38 DBIx::Class::Storage::DBI::ODBC::Microsoft_SQL_Server - Support specific
39 to Microsoft SQL Server over ODBC
43 This class implements support specific to Microsoft SQL Server over ODBC,
44 including auto-increment primary keys and SQL::Abstract::Limit dialect. It
45 is loaded automatically by by DBIx::Class::Storage::DBI::ODBC when it
46 detects a MSSQL back-end.
48 =head1 IMPLEMENTATION NOTES
50 Microsoft SQL Server supports three methods of retrieving the IDENTITY
51 value for inserted row: IDENT_CURRENT, @@IDENTITY, and SCOPE_IDENTITY().
52 SCOPE_IDENTITY is used here because it is the safest. However, it must
53 be called is the same execute statement, not just the same connection.
55 So, this implementation appends a SELECT SCOPE_IDENTITY() statement
56 onto each INSERT to accommodate that requirement.
60 Marc Mims C<< <marc@questright.com> >>
64 You may distribute this code under the same terms as Perl itself.