MSSQL/Storage/Sybase.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 12 / 12 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« MSSQL/Storage/ODBC.pm ↑ Summary MSSQL/Storage/Sybase/DateTime/Format.pm »
1 package DBIO::MSSQL::Storage::Sybase;
2 # ABSTRACT: Support for Microsoft SQL Server via DBD::Sybase
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use base qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
8 DBIO::Sybase::Storage
9 DBIO::MSSQL::Storage
10 1 /;
11 use mro 'c3';
12  
13 use DBIO::Carp;
14 use version ();
15 use namespace::clean;
16  
17  
18 __PACKAGE__->datetime_parser_type(
19 'DBIO::MSSQL::Storage::Sybase::DateTime::Format'
20 );
21  
22 sub _rebless {
23 my $self = shift;
24 my $dbh = $self->_get_dbh;
25  
26 return if ref $self ne __PACKAGE__;
27 if (not $self->_use_typeless_placeholders) {
28 carp_once <<'EOF' unless $ENV{DBIO_MSSQL_FREETDS_LOWVER_NOWARN};
29 Placeholders do not seem to be supported in your configuration of
30 DBD::Sybase/FreeTDS.
31  
32 This means you are taking a large performance hit, as caching of prepared
33 statements is disabled.
34  
35 Make sure to configure your server with "tds version" of 8.0 or 7.0 in
36 /etc/freetds/freetds.conf .
37  
38 To turn off this warning, set the DBIO_MSSQL_FREETDS_LOWVER_NOWARN environment
39 variable.
40 EOF
41 require
42 DBIO::MSSQL::Storage::Sybase::NoBindVars;
43 bless $self,
44 'DBIO::MSSQL::Storage::Sybase::NoBindVars';
45 $self->_rebless;
46 }
47 }
48  
49 sub _init {
50 my $self = shift;
51  
52 $self->next::method(@_);
53  
54 # work around massively broken freetds versions after 0.82
55 # - explicitly no scope_identity
56 # - no sth caching
57 #
58 # warn about the fact as well, do not provide a mechanism to shut it up
59 #
60 # Parse as a dotted version so modern FreeTDS strings like "1.3.17" are not
61 # coerced to a number (which truncates at the second dot and warns "isn't
62 # numeric"). An undeterminable version (0/undef) keeps the historic 999
63 # sentinel so it is still treated as a new/buggy build.
64 if ($self->_using_freetds) {
65 my $ver = $self->_using_freetds_version || 999;
66 if (version->parse("v$ver") > version->parse('v0.82')) {
67 carp_once(
68 "Your DBD::Sybase was compiled against buggy FreeTDS version $ver. "
69 . 'Statement caching does not work and will be disabled.'
70 );
71  
72 $self->_identity_method('@@identity');
73 $self->_no_scope_identity_query(1);
74 $self->disable_sth_caching(1);
75 }
76 }
77 }
78  
79 # invoked only if DBD::Sybase is compiled against FreeTDS
80 sub _set_autocommit_stmt {
81 my ($self, $on) = @_;
82  
83 return 'SET IMPLICIT_TRANSACTIONS ' . ($on ? 'OFF' : 'ON');
84 }
85  
86 sub _get_server_version {
87 my $self = shift;
88  
89 my $product_version = $self->_get_dbh->selectrow_hashref('master.dbo.xp_msver ProductVersion');
90  
91 if ((my $version = $product_version->{Character_Value}) =~ /^(\d+)\./) {
92 return $version;
93 }
94 else {
95 $self->throw_exception(
96 "MSSQL Version Retrieval Failed, Your ProductVersion's Character_Value is missing or malformed!"
97 );
98 }
99 }
100  
101  
102 sub connect_call_datetime_setup {
103 my $self = shift;
104 my $dbh = $self->_get_dbh;
105  
106 if ($dbh->can('syb_date_fmt')) {
107 # amazingly, this works with FreeTDS
108 $dbh->syb_date_fmt('ISO_strict');
109 }
110 else{
111 carp_once
112 'Your DBD::Sybase is too old to support '
113 . 'DBIO::InflateColumn::DateTime, please upgrade!';
114 }
115 }
116  
117  
118 1;
119  
120 __END__
121  
122 =pod
123  
124 =encoding UTF-8
125  
126 =head1 NAME
127  
128 DBIO::MSSQL::Storage::Sybase - Support for Microsoft SQL Server via DBD::Sybase
129  
130 =head1 VERSION
131  
132 version 0.900001
133  
134 =head1 DESCRIPTION
135  
136 Storage driver for Microsoft SQL Server accessed via L<DBD::Sybase>
137 (including FreeTDS-based connections). Inherits from both
138 L<DBIO::Sybase::Storage> and L<DBIO::MSSQL::Storage>.
139  
140 On connect, the driver checks whether your L<DBD::Sybase> build supports
141 placeholders. If not, the storage is reblessed to
142 C<DBIO::MSSQL::Storage::Sybase::NoBindVars>. FreeTDS versions above 0.82
143 have known statement-caching bugs; the driver detects these and disables
144 statement caching automatically.
145  
146 =head1 METHODS
147  
148 =head2 connect_call_datetime_setup
149  
150 Used as:
151  
152 on_connect_call => 'datetime_setup'
153  
154 In L<connect_info|DBIO::Storage::DBI/connect_info> to set:
155  
156 $dbh->syb_date_fmt('ISO_strict'); # output fmt: 2004-08-21T14:36:48.080Z
157  
158 On connection for use with L<DBIO::InflateColumn::DateTime>
159  
160 This works for both C<DATETIME> and C<SMALLDATETIME> columns, although
161 C<SMALLDATETIME> columns only have minute precision.
162  
163 =head1 SEE ALSO
164  
165 =over
166  
167 =item * L<DBIO::MSSQL> - MSSQL schema component
168  
169 =item * L<DBIO::MSSQL::Storage> - MSSQL storage base class
170  
171 =item * L<DBIO::Sybase::Storage> - Sybase storage base class
172  
173 =item * L<DBIO::Sybase::Storage::FreeTDS> - FreeTDS connection layer
174  
175 =back
176  
177 =head1 AUTHOR
178  
179 DBIO & DBIx::Class Authors
180  
181 =head1 COPYRIGHT AND LICENSE
182  
183 Copyright (C) 2026 DBIO Authors
184 Portions Copyright (C) 2005-2025 DBIx::Class Authors
185 Based on DBIx::Class, heavily modified.
186  
187 This is free software; you can redistribute it and/or modify it under
188 the same terms as the Perl 5 programming language system itself.
189  
190 =cut
« MSSQL/Storage/ODBC.pm ↑ Summary MSSQL/Storage/Sybase/DateTime/Format.pm »