1 package DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server;
7 DBIx::Class::Storage::DBI::ADO
8 DBIx::Class::Storage::DBI::MSSQL
14 DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server - Support for Microsoft
15 SQL Server via DBD::ADO
19 This subclass supports MSSQL server connections via L<DBD::ADO>.
23 The MSSQL specific functionality is provided by
24 L<DBIx::Class::Storage::DBI::MSSQL>.
28 dbi:ADO:provider=sqlncli10;server=EEEBOX\SQLEXPRESS
34 C<_identity_method> is set to C<@@identity>, as C<SCOPE_IDENTITY()> doesn't work
35 with L<DBD::ADO>. See L<DBIx::Class::Storage::DBI::MSSQL/IMPLEMENTATION NOTES>
36 for caveats regarding this.
40 There is a bug with MSSQL ADO providers where data gets truncated based on the
41 size of the bind sizes in the first prepare call:
43 L<https://rt.cpan.org/Ticket/Display.html?id=52048>
45 The C<ado_size> workaround is used (see L<DBD::ADO/"ADO Providers">) with the
46 approximate maximum size of the data_type of the bound column, or 8000 (maximum
47 VARCHAR size) if the data_type is not available.
49 This code is incomplete and may be buggy. Particularly, C<VARCHAR(MAX)> is not
50 supported yet. The data_type list for other DBs is also incomplete. Please
51 report problems (and send patches.)
53 =head2 fractional seconds
55 Fractional seconds with L<DBIx::Class::InflateColumn::DateTime> are not
56 currently supported, datetimes are truncated at the second.
60 __PACKAGE__->datetime_parser_type (
61 'DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server::DateTime::Format'
66 $self->_identity_method('@@identity');
69 # work around a bug in the ADO driver - use the max VARCHAR size for all
70 # binds that do not specify one via bind_attributes_by_data_type()
71 sub _dbi_attrs_for_bind {
72 my $attrs = shift->next::method(@_);
75 $_->{ado_size} ||= 8000 if $_;
81 sub bind_attribute_by_data_type {
82 my ($self, $data_type) = @_;
84 ($data_type = lc($data_type)) =~ s/\s+.*//;
87 $self->_mssql_max_data_type_representation_size_in_bytes->{$data_type};
90 $res->{ado_size} = $max_size if $max_size;
96 # XXX needs to support varchar(max) and varbinary(max)
97 sub _mssql_max_data_type_representation_size_in_bytes {
100 my $blob_max = $self->_get_dbh->{LongReadLen} || 32768;
122 uniqueidentifier => 100,
129 datetimeoffset => 100,
130 smalldatetime => 100,
137 xml => $blob_max, # ???
139 # some non-MSSQL types
148 package # hide from PAUSE
149 DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server::DateTime::Format;
151 my $datetime_format = '%m/%d/%Y %I:%M:%S %p';
156 require DateTime::Format::Strptime;
157 $datetime_parser ||= DateTime::Format::Strptime->new(
158 pattern => $datetime_format,
161 return $datetime_parser->parse_datetime(shift);
164 sub format_datetime {
166 require DateTime::Format::Strptime;
167 $datetime_parser ||= DateTime::Format::Strptime->new(
168 pattern => $datetime_format,
171 return $datetime_parser->format_datetime(shift);
178 See L<DBIx::Class/AUTHOR> and L<DBIx::Class/CONTRIBUTORS>.
182 You may distribute this code under the same terms as Perl itself.