minor changes
[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 {
18 my ($self, $source) = @_;
8bcd9ece 19
b3857e35 20 my $bind_attributes;
21 foreach my $column ($source->columns) {
8bcd9ece 22
b3857e35 23 my $data_type = $source->column_info($column)->{data_type} || '';
24 $bind_attributes->{$column} = $self->bind_attribute_by_data_type($data_type)
25 if $data_type;
26 $bind_attributes->{$column}{ado_size} ||= 8000; # max VARCHAR
27 }
28
29 return $bind_attributes;
30}
31
32sub bind_attribute_by_data_type {
33 my ($self, $data_type) = @_;
34
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 +{
52 char => 8000,
53 varchar => 8000,
54 binary => 8000,
55 varbinary => 8000,
56 nchar => 8000,
57 nvarchar => 8000,
58 numeric => 100,
59 smallint => 100,
60 tinyint => 100,
61 smallmoney => 100,
62 bigint => 100,
63 bit => 100,
64 decimal => 100,
65 int => 100,
66 money => 100,
67 float => 100,
68 real => 100,
748eb620 69 uniqueidentifier => 100,
b3857e35 70 ntext => $blob_max,
71 text => $blob_max,
72 image => $blob_max,
73 date => 100,
74 datetime => 100,
75 datetime2 => 100,
76 datetimeoffset => 100,
77 smalldatetime => 100,
78 time => 100,
79 timestamp => 100,
80 }
8bcd9ece 81}
82
4ffa5700 831;
84
85=head1 NAME
86
9f0c231f 87DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server - Support for Microsoft
4ffa5700 88SQL Server via DBD::ADO
89
90=head1 SYNOPSIS
91
92This subclass supports MSSQL server connections via L<DBD::ADO>.
93
94=head1 DESCRIPTION
95
96The MSSQL specific functionality is provided by
97L<DBIx::Class::Storage::DBI::MSSQL>.
98
99C<_identity_method> is set to C<@@identity>, as C<SCOPE_IDENTITY()> doesn't work
100with L<DBD::ADO>. See L<DBIx::Class::Storage::DBI::MSSQL/IMPLEMENTATION NOTES>
101for caveats regarding this.
102
103=head1 AUTHOR
104
105See L<DBIx::Class/CONTRIBUTORS>.
106
107=head1 LICENSE
108
109You may distribute this code under the same terms as Perl itself.
110
111=cut