Fix some mssql shortcommings when confronted with the new subequeried prefetch sql
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / MSSQL.pm
1 package DBIx::Class::Storage::DBI::MSSQL;
2
3 use strict;
4 use warnings;
5
6 use base qw/DBIx::Class::Storage::DBI::AmbiguousGlob DBIx::Class::Storage::DBI/;
7
8 __PACKAGE__->sql_maker_class('DBIx::Class::SQLAHacks::MSSQL');
9
10 sub _dbh_last_insert_id {
11   my ($self, $dbh, $source, $col) = @_;
12   my ($id) = $dbh->selectrow_array('SELECT SCOPE_IDENTITY()');
13   return $id;
14 }
15
16 sub build_datetime_parser {
17   my $self = shift;
18   my $type = "DateTime::Format::Strptime";
19   eval "use ${type}";
20   $self->throw_exception("Couldn't load ${type}: $@") if $@;
21   return $type->new( pattern => '%Y-%m-%d %H:%M:%S' );  # %F %T
22 }
23
24 sub sqlt_type { 'SQLServer' }
25
26 sub _sql_maker_opts {
27     my ( $self, $opts ) = @_;
28
29     if ( $opts ) {
30         $self->{_sql_maker_opts} = { %$opts };
31     }
32
33     return { limit_dialect => 'Top', %{$self->{_sql_maker_opts}||{}} };
34 }
35
36 1;
37
38 =head1 NAME
39
40 DBIx::Class::Storage::DBI::MSSQL - Storage::DBI subclass for MSSQL
41
42 =head1 SYNOPSIS
43
44 This subclass supports MSSQL, and can in theory be used directly
45 via the C<storage_type> mechanism:
46
47   $schema->storage_type('::DBI::MSSQL');
48   $schema->connect_info('dbi:....', ...);
49
50 However, as there is no L<DBD::MSSQL>, you will probably want to use
51 one of the other DBD-specific MSSQL classes, such as
52 L<DBIx::Class::Storage::DBI::Sybase::MSSQL>.  These classes will
53 merge this class with a DBD-specific class to obtain fully
54 correct behavior for your scenario.
55
56 =head1 METHODS
57
58 =head2 last_insert_id
59
60 =head2 sqlt_type
61
62 =head2 build_datetime_parser
63
64 The resulting parser handles the MSSQL C<DATETIME> type, but is almost
65 certainly not sufficient for the other MSSQL 2008 date/time types.
66
67 =head1 AUTHORS
68
69 Brian Cassidy <bricas@cpan.org>
70
71 =head1 LICENSE
72
73 You may distribute this code under the same terms as Perl itself.
74
75 =cut