Commit | Line | Data |
4ffa5700 |
1 | package DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use base qw/ |
7 | DBIx::Class::Storage::DBI::ADO |
8 | DBIx::Class::Storage::DBI::MSSQL |
9 | /; |
10 | use mro 'c3'; |
11 | |
12 | sub _rebless { |
13 | my $self = shift; |
14 | $self->_identity_method('@@identity'); |
15 | } |
16 | |
b3857e35 |
17 | sub 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 | |
32 | sub 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 |
45 | sub _mssql_max_data_type_representation_size_in_bytes { |
46 | my $self = shift; |
47 | |
48 | my $blob_max = $self->_get_dbh->{LongReadLen} || 32768; |
49 | |
50 | return +{ |
51 | char => 8000, |
52 | varchar => 8000, |
53 | binary => 8000, |
54 | varbinary => 8000, |
55 | nchar => 8000, |
56 | nvarchar => 8000, |
57 | numeric => 100, |
58 | smallint => 100, |
59 | tinyint => 100, |
60 | smallmoney => 100, |
61 | bigint => 100, |
62 | bit => 100, |
63 | decimal => 100, |
64 | int => 100, |
65 | money => 100, |
66 | float => 100, |
67 | real => 100, |
68 | ntext => $blob_max, |
69 | text => $blob_max, |
70 | image => $blob_max, |
71 | date => 100, |
72 | datetime => 100, |
73 | datetime2 => 100, |
74 | datetimeoffset => 100, |
75 | smalldatetime => 100, |
76 | time => 100, |
77 | timestamp => 100, |
78 | } |
8bcd9ece |
79 | } |
80 | |
4ffa5700 |
81 | 1; |
82 | |
83 | =head1 NAME |
84 | |
9f0c231f |
85 | DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server - Support for Microsoft |
4ffa5700 |
86 | SQL Server via DBD::ADO |
87 | |
88 | =head1 SYNOPSIS |
89 | |
90 | This subclass supports MSSQL server connections via L<DBD::ADO>. |
91 | |
92 | =head1 DESCRIPTION |
93 | |
94 | The MSSQL specific functionality is provided by |
95 | L<DBIx::Class::Storage::DBI::MSSQL>. |
96 | |
97 | C<_identity_method> is set to C<@@identity>, as C<SCOPE_IDENTITY()> doesn't work |
98 | with L<DBD::ADO>. See L<DBIx::Class::Storage::DBI::MSSQL/IMPLEMENTATION NOTES> |
99 | for caveats regarding this. |
100 | |
101 | =head1 AUTHOR |
102 | |
103 | See L<DBIx::Class/CONTRIBUTORS>. |
104 | |
105 | =head1 LICENSE |
106 | |
107 | You may distribute this code under the same terms as Perl itself. |
108 | |
109 | =cut |