1 package DBIx::Class::Storage::DBI::ODBC::Microsoft_SQL_Server;
5 use base qw/DBIx::Class::Storage::DBI/;
7 sub _prep_for_execute {
9 my ($op, $extra_bind, $ident, $args) = @_;
11 my ($sql, $bind) = $self->SUPER::_prep_for_execute(@_);
12 $sql .= ';SELECT SCOPE_IDENTITY()' if $op eq 'insert';
18 my ($self, $source, $to_insert) = @_;
20 my $bind_attributes = $self->source_bind_attributes($source);
21 my (undef, $sth) = $self->_execute( 'insert' => [], $source, $bind_attributes, $to_insert);
22 $self->{_scope_identity} = $sth->fetchrow_array;
27 sub last_insert_id { shift->{_scope_identity} }
29 sub sqlt_type { 'SQLServer' }
32 my ( $self, $opts ) = @_;
35 $self->{_sql_maker_opts} = { %$opts };
38 return { limit_dialect => 'Top', %{$self->{_sql_maker_opts}||{}} };
41 sub build_datetime_parser {
43 my $type = "DateTime::Format::Strptime";
45 $self->throw_exception("Couldn't load ${type}: $@") if $@;
46 return $type->new( pattern => '%F %T' );
55 DBIx::Class::Storage::DBI::ODBC::Microsoft_SQL_Server - Support specific
56 to Microsoft SQL Server over ODBC
60 This class implements support specific to Microsoft SQL Server over ODBC,
61 including auto-increment primary keys and SQL::Abstract::Limit dialect. It
62 is loaded automatically by by DBIx::Class::Storage::DBI::ODBC when it
63 detects a MSSQL back-end.
65 =head1 IMPLEMENTATION NOTES
67 Microsoft SQL Server supports three methods of retrieving the IDENTITY
68 value for inserted row: IDENT_CURRENT, @@IDENTITY, and SCOPE_IDENTITY().
69 SCOPE_IDENTITY is used here because it is the safest. However, it must
70 be called is the same execute statement, not just the same connection.
72 So, this implementation appends a SELECT SCOPE_IDENTITY() statement
73 onto each INSERT to accommodate that requirement.
83 =head2 build_datetime_parser
85 The resulting parser handles the MSSQL C<DATETIME> type, but is almost
86 certainly not sufficient for the other MSSQL 2008 date/time types.
90 Marc Mims C<< <marc@questright.com> >>
94 You may distribute this code under the same terms as Perl itself.