X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI%2FMSSQL.pm;h=40afe76607663593f11e85840f1be120fcba1c46;hb=a49fe31273f9306254dd3d0a29cbf765146fcfe0;hp=7a30b65f7467e455b8e01d9d0f0dc002cfb2d504;hpb=843f8ecda2d9885b79402416f048016c1ecc4114;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/Storage/DBI/MSSQL.pm b/lib/DBIx/Class/Storage/DBI/MSSQL.pm index 7a30b65..40afe76 100644 --- a/lib/DBIx/Class/Storage/DBI/MSSQL.pm +++ b/lib/DBIx/Class/Storage/DBI/MSSQL.pm @@ -1,39 +1,73 @@ -package DBIx::Class::Storage::DBI::MSSQL; - -use strict; -use warnings; - -use base qw/DBIx::Class::Storage::DBI/; - -# __PACKAGE__->load_components(qw/PK::Auto/); - -sub last_insert_id { - my( $id ) = $_[0]->_dbh->selectrow_array('SELECT @@IDENTITY' ); - return $id; -} - -1; - -=head1 NAME - -DBIx::Class::Storage::DBI::MSSQL - Automatic primary key class for MSSQL - -=head1 SYNOPSIS - - # In your table classes - __PACKAGE__->load_components(qw/PK::Auto Core/); - __PACKAGE__->set_primary_key('id'); - -=head1 DESCRIPTION - -This class implements autoincrements for MSSQL. - -=head1 AUTHORS - -Brian Cassidy - -=head1 LICENSE - -You may distribute this code under the same terms as Perl itself. - -=cut +package DBIx::Class::Storage::DBI::MSSQL; + +use strict; +use warnings; + +use base qw/DBIx::Class::Storage::DBI/; + +sub _dbh_last_insert_id { + my ($self, $dbh, $source, $col) = @_; + my ($id) = $dbh->selectrow_array('SELECT SCOPE_IDENTITY()'); + return $id; +} + +sub build_datetime_parser { + my $self = shift; + my $type = "DateTime::Format::Strptime"; + eval "use ${type}"; + $self->throw_exception("Couldn't load ${type}: $@") if $@; + return $type->new( pattern => '%Y-%m-%d %H:%M:%S' ); # %F %T +} + +sub sqlt_type { 'SQLServer' } + +sub _sql_maker_opts { + my ( $self, $opts ) = @_; + + if ( $opts ) { + $self->{_sql_maker_opts} = { %$opts }; + } + + return { limit_dialect => 'Top', %{$self->{_sql_maker_opts}||{}} }; +} + +1; + +=head1 NAME + +DBIx::Class::Storage::DBI::MSSQL - Storage::DBI subclass for MSSQL + +=head1 SYNOPSIS + +This subclass supports MSSQL, and can in theory be used directly +via the C mechanism: + + $schema->storage_type('::DBI::MSSQL'); + $schema->connect_info('dbi:....', ...); + +However, as there is no L, you will probably want to use +one of the other DBD-specific MSSQL classes, such as +L. These classes will +merge this class with a DBD-specific class to obtain fully +correct behavior for your scenario. + +=head1 METHODS + +=head2 last_insert_id + +=head2 sqlt_type + +=head2 build_datetime_parser + +The resulting parser handles the MSSQL C type, but is almost +certainly not sufficient for the other MSSQL 2008 date/time types. + +=head1 AUTHORS + +Brian Cassidy + +=head1 LICENSE + +You may distribute this code under the same terms as Perl itself. + +=cut