Add extra test blob type
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / ADO / Microsoft_SQL_Server.pm
CommitLineData
4ffa5700 1package DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server;
2
3use strict;
4use warnings;
5
6use base qw/
7 DBIx::Class::Storage::DBI::ADO
8 DBIx::Class::Storage::DBI::MSSQL
9/;
10use mro 'c3';
11
12sub _rebless {
13 my $self = shift;
14 $self->_identity_method('@@identity');
15}
16
b3857e35 17sub source_bind_attributes {
335b0f6c 18 my $self = shift;
19 my ($source) = @_;
8bcd9ece 20
335b0f6c 21 my $bind_attributes = $self->next::method(@_);
8bcd9ece 22
335b0f6c 23 foreach my $column ($source->columns) {
b3857e35 24 $bind_attributes->{$column}{ado_size} ||= 8000; # max VARCHAR
25 }
26
27 return $bind_attributes;
28}
29
30sub bind_attribute_by_data_type {
31 my ($self, $data_type) = @_;
32
48012f35 33 ($data_type = lc($data_type)) =~ s/\s+.*//;
34
b3857e35 35 my $max_size =
36 $self->_mssql_max_data_type_representation_size_in_bytes->{$data_type};
37
38 my $res = {};
39 $res->{ado_size} = $max_size if $max_size;
40
41 return $res;
42}
43
44# approximate
748eb620 45# XXX needs to support varchar(max) and varbinary(max)
b3857e35 46sub _mssql_max_data_type_representation_size_in_bytes {
47 my $self = shift;
48
49 my $blob_max = $self->_get_dbh->{LongReadLen} || 32768;
50
51 return +{
48012f35 52# MSSQL types
b3857e35 53 char => 8000,
54 varchar => 8000,
55 binary => 8000,
56 varbinary => 8000,
57 nchar => 8000,
58 nvarchar => 8000,
59 numeric => 100,
60 smallint => 100,
61 tinyint => 100,
62 smallmoney => 100,
63 bigint => 100,
64 bit => 100,
65 decimal => 100,
48012f35 66 integer => 100,
b3857e35 67 int => 100,
68 money => 100,
69 float => 100,
70 real => 100,
748eb620 71 uniqueidentifier => 100,
b3857e35 72 ntext => $blob_max,
73 text => $blob_max,
74 image => $blob_max,
75 date => 100,
76 datetime => 100,
77 datetime2 => 100,
78 datetimeoffset => 100,
79 smalldatetime => 100,
80 time => 100,
81 timestamp => 100,
48012f35 82 cursor => 100,
83 hierarchyid => 100,
84 sql_variant => 100,
85 table => 100,
86 xml => $blob_max, # ???
87
88# some non-MSSQL types
89 serial => 100,
90 bigserial => 100,
91 varchar2 => 8000,
92 blob => $blob_max,
93 clob => $blob_max,
b3857e35 94 }
8bcd9ece 95}
96
4ffa5700 971;
98
99=head1 NAME
100
9f0c231f 101DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server - Support for Microsoft
4ffa5700 102SQL Server via DBD::ADO
103
104=head1 SYNOPSIS
105
106This subclass supports MSSQL server connections via L<DBD::ADO>.
107
108=head1 DESCRIPTION
109
110The MSSQL specific functionality is provided by
111L<DBIx::Class::Storage::DBI::MSSQL>.
112
48012f35 113=head2 CAVEATS
114
115=head3 identities
116
4ffa5700 117C<_identity_method> is set to C<@@identity>, as C<SCOPE_IDENTITY()> doesn't work
118with L<DBD::ADO>. See L<DBIx::Class::Storage::DBI::MSSQL/IMPLEMENTATION NOTES>
119for caveats regarding this.
120
48012f35 121=head3 truncation bug
122
123There is a bug with MSSQL ADO providers where data gets truncated based on the
83677d07 124size of the bind sizes in the first prepare call:
48012f35 125
126L<https://rt.cpan.org/Ticket/Display.html?id=52048>
127
128The C<ado_size> workaround is used (see L<DBD::ADO/"ADO Providers">) with the
129approximate maximum size of the data_type of the bound column, or 8000 (maximum
130VARCHAR size) if the data_type is not available.
131
132This code is incomplete and may be buggy. Particularly, C<VARCHAR(MAX)> is not
133supported yet. The data_type list for other DBs is also incomplete. Please
134report problems (and send patches.)
135
4ffa5700 136=head1 AUTHOR
137
138See L<DBIx::Class/CONTRIBUTORS>.
139
140=head1 LICENSE
141
142You may distribute this code under the same terms as Perl itself.
143
144=cut