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