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.
62 $self->_identity_method('@@identity');
65 sub source_bind_attributes {
69 my $bind_attributes = $self->next::method(@_);
71 foreach my $column ($source->columns) {
72 $bind_attributes->{$column}{ado_size} ||= 8000; # max VARCHAR
75 return $bind_attributes;
78 sub bind_attribute_by_data_type {
79 my ($self, $data_type) = @_;
81 ($data_type = lc($data_type)) =~ s/\s+.*//;
84 $self->_mssql_max_data_type_representation_size_in_bytes->{$data_type};
87 $res->{ado_size} = $max_size if $max_size;
93 # XXX needs to support varchar(max) and varbinary(max)
94 sub _mssql_max_data_type_representation_size_in_bytes {
97 my $blob_max = $self->_get_dbh->{LongReadLen} || 32768;
119 uniqueidentifier => 100,
126 datetimeoffset => 100,
127 smalldatetime => 100,
134 xml => $blob_max, # ???
136 # some non-MSSQL types
145 sub datetime_parser_type {
146 'DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server::DateTime::Format'
149 package # hide from PAUSE
150 DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server::DateTime::Format;
152 my $datetime_format = '%m/%d/%Y %I:%M:%S %p';
157 require DateTime::Format::Strptime;
158 $datetime_parser ||= DateTime::Format::Strptime->new(
159 pattern => $datetime_format,
162 return $datetime_parser->parse_datetime(shift);
165 sub format_datetime {
167 require DateTime::Format::Strptime;
168 $datetime_parser ||= DateTime::Format::Strptime->new(
169 pattern => $datetime_format,
172 return $datetime_parser->format_datetime(shift);
179 See L<DBIx::Class/AUTHOR> and L<DBIx::Class/CONTRIBUTORS>.
183 You may distribute this code under the same terms as Perl itself.