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