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 | |
c1e5a9ac |
68 | # invoked only if DBD::Sybase is compiled against FreeTDS |
69 | sub _set_autocommit_stmt { |
70 | my ($self, $on) = @_; |
b90d7eba |
71 | |
c1e5a9ac |
72 | return 'SET IMPLICIT_TRANSACTIONS ' . ($on ? 'OFF' : 'ON'); |
b90d7eba |
73 | } |
74 | |
6d766626 |
75 | sub _get_server_version { |
ff153e24 |
76 | my $self = shift; |
77 | |
4282b6f8 |
78 | my $product_version = $self->_get_dbh->selectrow_hashref('master.dbo.xp_msver ProductVersion'); |
ff153e24 |
79 | |
89f85d82 |
80 | if ((my $version = $product_version->{Character_Value}) =~ /^(\d+)\./) { |
6d766626 |
81 | return $version; |
82 | } |
83 | else { |
84 | $self->throw_exception( |
85 | "MSSQL Version Retrieval Failed, Your ProductVersion's Character_Value is missing or malformed!" |
89f85d82 |
86 | ); |
ff153e24 |
87 | } |
ff153e24 |
88 | } |
89 | |
fb95dc4d |
90 | =head2 connect_call_datetime_setup |
91 | |
92 | Used as: |
93 | |
94 | on_connect_call => 'datetime_setup' |
95 | |
96 | In L<connect_info|DBIx::Class::Storage::DBI/connect_info> to set: |
97 | |
98 | $dbh->syb_date_fmt('ISO_strict'); # output fmt: 2004-08-21T14:36:48.080Z |
99 | |
100 | On connection for use with L<DBIx::Class::InflateColumn::DateTime> |
101 | |
102 | This works for both C<DATETIME> and C<SMALLDATETIME> columns, although |
103 | C<SMALLDATETIME> columns only have minute precision. |
104 | |
105 | =cut |
106 | |
70c28808 |
107 | sub connect_call_datetime_setup { |
108 | my $self = shift; |
109 | my $dbh = $self->_get_dbh; |
110 | |
111 | if ($dbh->can('syb_date_fmt')) { |
112 | # amazingly, this works with FreeTDS |
113 | $dbh->syb_date_fmt('ISO_strict'); |
114 | } |
115 | else{ |
116 | carp_once |
117 | 'Your DBD::Sybase is too old to support ' |
118 | . 'DBIx::Class::InflateColumn::DateTime, please upgrade!'; |
fb95dc4d |
119 | } |
120 | } |
121 | |
fb95dc4d |
122 | |
123 | package # hide from PAUSE |
124 | DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::DateTime::Format; |
125 | |
126 | my $datetime_parse_format = '%Y-%m-%dT%H:%M:%S.%3NZ'; |
127 | my $datetime_format_format = '%Y-%m-%d %H:%M:%S.%3N'; # %F %T |
128 | |
129 | my ($datetime_parser, $datetime_formatter); |
130 | |
131 | sub parse_datetime { |
132 | shift; |
133 | require DateTime::Format::Strptime; |
134 | $datetime_parser ||= DateTime::Format::Strptime->new( |
135 | pattern => $datetime_parse_format, |
136 | on_error => 'croak', |
137 | ); |
138 | return $datetime_parser->parse_datetime(shift); |
139 | } |
140 | |
141 | sub format_datetime { |
142 | shift; |
143 | require DateTime::Format::Strptime; |
144 | $datetime_formatter ||= DateTime::Format::Strptime->new( |
145 | pattern => $datetime_format_format, |
146 | on_error => 'croak', |
147 | ); |
148 | return $datetime_formatter->format_datetime(shift); |
149 | } |
150 | |
98464041 |
151 | 1; |
152 | |
5a77aa8b |
153 | =head1 AUTHOR |
98464041 |
154 | |
b7505130 |
155 | See L<DBIx::Class/CONTRIBUTORS>. |
98464041 |
156 | |
157 | =head1 LICENSE |
158 | |
159 | You may distribute this code under the same terms as Perl itself. |
160 | |
161 | =cut |