Commit | Line | Data |
98464041 |
1 | package DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server; |
2 | |
3 | use strict; |
4 | use warnings; |
2ad62d97 |
5 | |
528accab |
6 | use base qw/ |
95787afe |
7 | DBIx::Class::Storage::DBI::Sybase |
5a77aa8b |
8 | DBIx::Class::Storage::DBI::MSSQL |
528accab |
9 | /; |
2ad62d97 |
10 | use mro 'c3'; |
9c1700e3 |
11 | |
70c28808 |
12 | use DBIx::Class::Carp; |
98464041 |
13 | |
c1e5a9ac |
14 | =head1 NAME |
15 | |
16 | DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server - Support for Microsoft |
17 | SQL Server via DBD::Sybase |
18 | |
19 | =head1 SYNOPSIS |
20 | |
21 | This subclass supports MSSQL server connections via L<DBD::Sybase>. |
22 | |
23 | =head1 DESCRIPTION |
24 | |
25 | This driver tries to determine whether your version of L<DBD::Sybase> and |
26 | supporting libraries (usually FreeTDS) support using placeholders, if not the |
27 | storage will be reblessed to |
28 | L<DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::NoBindVars>. |
29 | |
30 | The MSSQL specific functionality is provided by |
31 | L<DBIx::Class::Storage::DBI::MSSQL>. |
32 | |
33 | =head1 METHODS |
34 | |
35 | =cut |
36 | |
6f7a118e |
37 | __PACKAGE__->datetime_parser_type( |
38 | 'DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::DateTime::Format' |
39 | ); |
40 | |
9b3dabe0 |
41 | sub _rebless { |
42 | my $self = shift; |
9ae966b9 |
43 | my $dbh = $self->_get_dbh; |
7379eb67 |
44 | |
918ab8ae |
45 | return if ref $self ne __PACKAGE__; |
bbdda281 |
46 | if (not $self->_use_typeless_placeholders) { |
70171cd7 |
47 | carp_once <<'EOF' unless $ENV{DBIC_MSSQL_FREETDS_LOWVER_NOWARN}; |
c1e5a9ac |
48 | Placeholders do not seem to be supported in your configuration of |
49 | DBD::Sybase/FreeTDS. |
50 | |
51 | This means you are taking a large performance hit, as caching of prepared |
52 | statements is disabled. |
53 | |
54 | Make sure to configure your server with "tds version" of 8.0 or 7.0 in |
55 | /etc/freetds/freetds.conf . |
56 | |
57 | To turn off this warning, set the DBIC_MSSQL_FREETDS_LOWVER_NOWARN environment |
58 | variable. |
59 | EOF |
918ab8ae |
60 | require |
61 | DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::NoBindVars; |
7379eb67 |
62 | bless $self, |
63 | 'DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::NoBindVars'; |
64 | $self->_rebless; |
65 | } |
d867eeda |
66 | } |
4966150b |
67 | |
0d6c550e |
68 | sub _init { |
69 | my $self = shift; |
70 | |
71 | $self->next::method(@_); |
72 | |
73 | # work around massively broken freetds versions after 0.82 |
74 | # - explicitly no scope_identity |
75 | # - no sth caching |
76 | # |
77 | # warn about the fact as well, do not provide a mechanism to shut it up |
78 | if ($self->_using_freetds and (my $ver = $self->_using_freetds_version||999) > 0.82) { |
79 | carp_once( |
80 | "Your DBD::Sybase was compiled against buggy FreeTDS version $ver. " |
81 | . 'Statement caching does not work and will be disabled.' |
82 | ); |
83 | |
84 | $self->_identity_method('@@identity'); |
85 | $self->_no_scope_identity_query(1); |
86 | $self->disable_sth_caching(1); |
87 | } |
88 | } |
89 | |
c1e5a9ac |
90 | # invoked only if DBD::Sybase is compiled against FreeTDS |
91 | sub _set_autocommit_stmt { |
92 | my ($self, $on) = @_; |
b90d7eba |
93 | |
c1e5a9ac |
94 | return 'SET IMPLICIT_TRANSACTIONS ' . ($on ? 'OFF' : 'ON'); |
b90d7eba |
95 | } |
96 | |
6d766626 |
97 | sub _get_server_version { |
ff153e24 |
98 | my $self = shift; |
99 | |
4282b6f8 |
100 | my $product_version = $self->_get_dbh->selectrow_hashref('master.dbo.xp_msver ProductVersion'); |
ff153e24 |
101 | |
89f85d82 |
102 | if ((my $version = $product_version->{Character_Value}) =~ /^(\d+)\./) { |
6d766626 |
103 | return $version; |
104 | } |
105 | else { |
106 | $self->throw_exception( |
107 | "MSSQL Version Retrieval Failed, Your ProductVersion's Character_Value is missing or malformed!" |
89f85d82 |
108 | ); |
ff153e24 |
109 | } |
ff153e24 |
110 | } |
111 | |
fb95dc4d |
112 | =head2 connect_call_datetime_setup |
113 | |
114 | Used as: |
115 | |
116 | on_connect_call => 'datetime_setup' |
117 | |
118 | In L<connect_info|DBIx::Class::Storage::DBI/connect_info> to set: |
119 | |
120 | $dbh->syb_date_fmt('ISO_strict'); # output fmt: 2004-08-21T14:36:48.080Z |
121 | |
122 | On connection for use with L<DBIx::Class::InflateColumn::DateTime> |
123 | |
124 | This works for both C<DATETIME> and C<SMALLDATETIME> columns, although |
125 | C<SMALLDATETIME> columns only have minute precision. |
126 | |
127 | =cut |
128 | |
70c28808 |
129 | sub connect_call_datetime_setup { |
130 | my $self = shift; |
131 | my $dbh = $self->_get_dbh; |
132 | |
133 | if ($dbh->can('syb_date_fmt')) { |
134 | # amazingly, this works with FreeTDS |
135 | $dbh->syb_date_fmt('ISO_strict'); |
136 | } |
137 | else{ |
138 | carp_once |
139 | 'Your DBD::Sybase is too old to support ' |
140 | . 'DBIx::Class::InflateColumn::DateTime, please upgrade!'; |
fb95dc4d |
141 | } |
142 | } |
143 | |
fb95dc4d |
144 | |
145 | package # hide from PAUSE |
146 | DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::DateTime::Format; |
147 | |
148 | my $datetime_parse_format = '%Y-%m-%dT%H:%M:%S.%3NZ'; |
8273e845 |
149 | my $datetime_format_format = '%Y-%m-%d %H:%M:%S.%3N'; # %F %T |
fb95dc4d |
150 | |
151 | my ($datetime_parser, $datetime_formatter); |
152 | |
153 | sub parse_datetime { |
154 | shift; |
155 | require DateTime::Format::Strptime; |
156 | $datetime_parser ||= DateTime::Format::Strptime->new( |
157 | pattern => $datetime_parse_format, |
158 | on_error => 'croak', |
159 | ); |
160 | return $datetime_parser->parse_datetime(shift); |
161 | } |
162 | |
163 | sub format_datetime { |
164 | shift; |
165 | require DateTime::Format::Strptime; |
166 | $datetime_formatter ||= DateTime::Format::Strptime->new( |
167 | pattern => $datetime_format_format, |
168 | on_error => 'croak', |
169 | ); |
170 | return $datetime_formatter->format_datetime(shift); |
171 | } |
172 | |
98464041 |
173 | 1; |
174 | |
5a77aa8b |
175 | =head1 AUTHOR |
98464041 |
176 | |
b7505130 |
177 | See L<DBIx::Class/CONTRIBUTORS>. |
98464041 |
178 | |
179 | =head1 LICENSE |
180 | |
181 | You may distribute this code under the same terms as Perl itself. |
182 | |
183 | =cut |