X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI%2FADO%2FMicrosoft_SQL_Server.pm;h=7e08098f499410fb5615d4fff144a2787c682759;hb=90d7422fc60a3bad71cc67dc20106ef68046664e;hp=3014c34736e36f16f0eac4fcd504d14ab2233f2a;hpb=335b0f6c285aa28d828172fda52daab0fb2e72e3;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/Storage/DBI/ADO/Microsoft_SQL_Server.pm b/lib/DBIx/Class/Storage/DBI/ADO/Microsoft_SQL_Server.pm index 3014c34..7e08098 100644 --- a/lib/DBIx/Class/Storage/DBI/ADO/Microsoft_SQL_Server.pm +++ b/lib/DBIx/Class/Storage/DBI/ADO/Microsoft_SQL_Server.pm @@ -9,27 +9,80 @@ use base qw/ /; use mro 'c3'; +=head1 NAME + +DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server - Support for Microsoft +SQL Server via DBD::ADO + +=head1 SYNOPSIS + +This subclass supports MSSQL server connections via L. + +=head1 DESCRIPTION + +The MSSQL specific functionality is provided by +L. + +=head1 EXAMPLE DSN + + dbi:ADO:provider=sqlncli10;server=EEEBOX\SQLEXPRESS + +=head1 CAVEATS + +=head2 identities + +C<_identity_method> is set to C<@@identity>, as C doesn't work +with L. See L +for caveats regarding this. + +=head2 truncation bug + +There is a bug with MSSQL ADO providers where data gets truncated based on the +size of the bind sizes in the first prepare call: + +L + +The C workaround is used (see L) with the +approximate maximum size of the data_type of the bound column, or 8000 (maximum +VARCHAR size) if the data_type is not available. + +This code is incomplete and may be buggy. Particularly, C is not +supported yet. The data_type list for other DBs is also incomplete. Please +report problems (and send patches.) + +=head2 fractional seconds + +Fractional seconds with L are not +currently supported, datetimes are truncated at the second. + +=cut + +__PACKAGE__->datetime_parser_type ( + 'DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server::DateTime::Format' +); + sub _rebless { my $self = shift; $self->_identity_method('@@identity'); } -sub source_bind_attributes { - my $self = shift; - my ($source) = @_; - - my $bind_attributes = $self->next::method(@_); +# work around a bug in the ADO driver - use the max VARCHAR size for all +# binds that do not specify one via bind_attributes_by_data_type() +sub _dbi_attrs_for_bind { + my $attrs = shift->next::method(@_); - foreach my $column ($source->columns) { - $bind_attributes->{$column}{ado_size} ||= 8000; # max VARCHAR + for (@$attrs) { + $_->{ado_size} ||= 8000 if $_; } - return $bind_attributes; + $attrs; } sub bind_attribute_by_data_type { my ($self, $data_type) = @_; + ($data_type = lc($data_type)) =~ s/\s+.*//; + my $max_size = $self->_mssql_max_data_type_representation_size_in_bytes->{$data_type}; @@ -47,6 +100,7 @@ sub _mssql_max_data_type_representation_size_in_bytes { my $blob_max = $self->_get_dbh->{LongReadLen} || 32768; return +{ +# MSSQL types char => 8000, varchar => 8000, binary => 8000, @@ -60,6 +114,7 @@ sub _mssql_max_data_type_representation_size_in_bytes { bigint => 100, bit => 100, decimal => 100, + integer => 100, int => 100, money => 100, float => 100, @@ -75,35 +130,56 @@ sub _mssql_max_data_type_representation_size_in_bytes { smalldatetime => 100, time => 100, timestamp => 100, + cursor => 100, + hierarchyid => 100, + sql_variant => 100, + table => 100, + xml => $blob_max, # ??? + +# some non-MSSQL types + serial => 100, + bigserial => 100, + varchar2 => 8000, + blob => $blob_max, + clob => $blob_max, } } -1; - -=head1 NAME - -DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server - Support for Microsoft -SQL Server via DBD::ADO - -=head1 SYNOPSIS +package # hide from PAUSE + DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server::DateTime::Format; -This subclass supports MSSQL server connections via L. +my $datetime_format = '%m/%d/%Y %I:%M:%S %p'; +my $datetime_parser; -=head1 DESCRIPTION +sub parse_datetime { + shift; + require DateTime::Format::Strptime; + $datetime_parser ||= DateTime::Format::Strptime->new( + pattern => $datetime_format, + on_error => 'croak', + ); + return $datetime_parser->parse_datetime(shift); +} -The MSSQL specific functionality is provided by -L. +sub format_datetime { + shift; + require DateTime::Format::Strptime; + $datetime_parser ||= DateTime::Format::Strptime->new( + pattern => $datetime_format, + on_error => 'croak', + ); + return $datetime_parser->format_datetime(shift); +} -C<_identity_method> is set to C<@@identity>, as C doesn't work -with L. See L -for caveats regarding this. +1; =head1 AUTHOR -See L. +See L and L. =head1 LICENSE You may distribute this code under the same terms as Perl itself. =cut +# vim:sts=2 sw=2: