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 | |
fb95dc4d |
12 | use Carp::Clan qw/^DBIx::Class/; |
9c1700e3 |
13 | use namespace::clean; |
98464041 |
14 | |
6f7a118e |
15 | __PACKAGE__->datetime_parser_type( |
16 | 'DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::DateTime::Format' |
17 | ); |
18 | |
9b3dabe0 |
19 | sub _rebless { |
20 | my $self = shift; |
9ae966b9 |
21 | my $dbh = $self->_get_dbh; |
7379eb67 |
22 | |
918ab8ae |
23 | return if ref $self ne __PACKAGE__; |
bbdda281 |
24 | if (not $self->_use_typeless_placeholders) { |
918ab8ae |
25 | require |
26 | DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::NoBindVars; |
7379eb67 |
27 | bless $self, |
28 | 'DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::NoBindVars'; |
29 | $self->_rebless; |
30 | } |
d867eeda |
31 | } |
4966150b |
32 | |
f244a815 |
33 | sub _run_connection_actions { |
d867eeda |
34 | my $self = shift; |
4966150b |
35 | |
d867eeda |
36 | # LongReadLen doesn't work with MSSQL through DBD::Sybase, and the default is |
37 | # huge on some versions of SQL server and can cause memory problems, so we |
95787afe |
38 | # fix it up here (see ::DBI::Sybase.pm) |
d867eeda |
39 | $self->set_textsize; |
f244a815 |
40 | |
41 | $self->next::method(@_); |
37b17a93 |
42 | } |
43 | |
b90d7eba |
44 | sub _dbh_begin_work { |
45 | my $self = shift; |
46 | |
47 | $self->_get_dbh->do('BEGIN TRAN'); |
48 | } |
49 | |
50 | sub _dbh_commit { |
51 | my $self = shift; |
6db5bdc6 |
52 | my $dbh = $self->_dbh |
53 | or $self->throw_exception('cannot COMMIT on a disconnected handle'); |
54 | $dbh->do('COMMIT'); |
b90d7eba |
55 | } |
56 | |
57 | sub _dbh_rollback { |
58 | my $self = shift; |
6db5bdc6 |
59 | my $dbh = $self->_dbh |
60 | or $self->throw_exception('cannot ROLLBACK on a disconnected handle'); |
61 | $dbh->do('ROLLBACK'); |
b90d7eba |
62 | } |
63 | |
6d766626 |
64 | sub _get_server_version { |
ff153e24 |
65 | my $self = shift; |
66 | |
4282b6f8 |
67 | my $product_version = $self->_get_dbh->selectrow_hashref('master.dbo.xp_msver ProductVersion'); |
ff153e24 |
68 | |
89f85d82 |
69 | if ((my $version = $product_version->{Character_Value}) =~ /^(\d+)\./) { |
6d766626 |
70 | return $version; |
71 | } |
72 | else { |
73 | $self->throw_exception( |
74 | "MSSQL Version Retrieval Failed, Your ProductVersion's Character_Value is missing or malformed!" |
89f85d82 |
75 | ); |
ff153e24 |
76 | } |
ff153e24 |
77 | } |
78 | |
fb95dc4d |
79 | =head2 connect_call_datetime_setup |
80 | |
81 | Used as: |
82 | |
83 | on_connect_call => 'datetime_setup' |
84 | |
85 | In L<connect_info|DBIx::Class::Storage::DBI/connect_info> to set: |
86 | |
87 | $dbh->syb_date_fmt('ISO_strict'); # output fmt: 2004-08-21T14:36:48.080Z |
88 | |
89 | On connection for use with L<DBIx::Class::InflateColumn::DateTime> |
90 | |
91 | This works for both C<DATETIME> and C<SMALLDATETIME> columns, although |
92 | C<SMALLDATETIME> columns only have minute precision. |
93 | |
94 | =cut |
95 | |
96 | { |
97 | my $old_dbd_warned = 0; |
98 | |
99 | sub connect_call_datetime_setup { |
100 | my $self = shift; |
101 | my $dbh = $self->_get_dbh; |
102 | |
103 | if ($dbh->can('syb_date_fmt')) { |
104 | # amazingly, this works with FreeTDS |
105 | $dbh->syb_date_fmt('ISO_strict'); |
106 | } elsif (not $old_dbd_warned) { |
107 | carp "Your DBD::Sybase is too old to support ". |
108 | "DBIx::Class::InflateColumn::DateTime, please upgrade!"; |
109 | $old_dbd_warned = 1; |
110 | } |
111 | } |
112 | } |
113 | |
fb95dc4d |
114 | |
115 | package # hide from PAUSE |
116 | DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::DateTime::Format; |
117 | |
118 | my $datetime_parse_format = '%Y-%m-%dT%H:%M:%S.%3NZ'; |
119 | my $datetime_format_format = '%Y-%m-%d %H:%M:%S.%3N'; # %F %T |
120 | |
121 | my ($datetime_parser, $datetime_formatter); |
122 | |
123 | sub parse_datetime { |
124 | shift; |
125 | require DateTime::Format::Strptime; |
126 | $datetime_parser ||= DateTime::Format::Strptime->new( |
127 | pattern => $datetime_parse_format, |
128 | on_error => 'croak', |
129 | ); |
130 | return $datetime_parser->parse_datetime(shift); |
131 | } |
132 | |
133 | sub format_datetime { |
134 | shift; |
135 | require DateTime::Format::Strptime; |
136 | $datetime_formatter ||= DateTime::Format::Strptime->new( |
137 | pattern => $datetime_format_format, |
138 | on_error => 'croak', |
139 | ); |
140 | return $datetime_formatter->format_datetime(shift); |
141 | } |
142 | |
98464041 |
143 | 1; |
144 | |
145 | =head1 NAME |
146 | |
5a77aa8b |
147 | DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server - Support for Microsoft |
148 | SQL Server via DBD::Sybase |
98464041 |
149 | |
150 | =head1 SYNOPSIS |
151 | |
5608593e |
152 | This subclass supports MSSQL server connections via L<DBD::Sybase>. |
98464041 |
153 | |
7379eb67 |
154 | =head1 DESCRIPTION |
d4483998 |
155 | |
7379eb67 |
156 | This driver tries to determine whether your version of L<DBD::Sybase> and |
157 | supporting libraries (usually FreeTDS) support using placeholders, if not the |
158 | storage will be reblessed to |
159 | L<DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::NoBindVars>. |
98464041 |
160 | |
7379eb67 |
161 | The MSSQL specific functionality is provided by |
162 | L<DBIx::Class::Storage::DBI::MSSQL>. |
7e8cecc1 |
163 | |
5a77aa8b |
164 | =head1 AUTHOR |
98464041 |
165 | |
b7505130 |
166 | See L<DBIx::Class/CONTRIBUTORS>. |
98464041 |
167 | |
168 | =head1 LICENSE |
169 | |
170 | You may distribute this code under the same terms as Perl itself. |
171 | |
172 | =cut |