SQLEngine/Driver/MSSQL.pm untested

filter: Statementstmt 0.0% 0 / 23 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 56 CC 4 SCAR 20.2
CC
4
Cov
0%
sql_limit
20.0
do_insert_with_sequence
2.0
seq_fetch_current
2.0
CRAP 7.5
1 =head1 NAME
2  
3 DBIx::SQLEngine::Driver::MSSQL - Support Microsoft SQL Server via DBD::ODBC
4  
5 =head1 SYNOPSIS
6  
7 B<DBI Wrapper>: Adds methods to a DBI database handle.
8  
9 my $sqldb = DBIx::SQLEngine->new( 'dbi:odbc:mycnxn' );
10
11 B<Portability Subclasses:> Uses driver's idioms or emulation.
12
13 $hash_ary = $sqldb->fetch_select(
14 table => 'students'
15 limit => 5, offset => 10
16 );
17  
18 =head1 DESCRIPTION
19  
20 This package provides a subclass of DBIx::SQLEngine which compensates for Microsoft SQL Server's idiosyncrasies.
21  
22 =head2 Under Development
23  
24 Note: this driver class has been added recently and not yet tested in real-world conditions.
25  
26 =head2 About Driver Subclasses
27  
28 You do not need to use this package directly; when you connect to a database, the SQLEngine object is automatically re-blessed in to the appropriate subclass.
29  
30 =cut
31  
32 ########################################################################
33  
34 package DBIx::SQLEngine::Driver::MSSQL;
35  
36 use strict;
37 use Carp;
38  
39 ########################################################################
40  
41 =head1 FETCHING DATA (SQL DQL)
42  
43 =head2 Methods Used By Complex Queries
44  
45 =over 4
46  
47 =item sql_limit()
48  
49 Adds support for SQL select limit clause.
50  
51 =back
52  
53 =cut
54  
55 sub sql_limit {
56 my $self = shift;
57 my ( $limit, $offset, $sql, @params ) = @_;
58  
59 # You can't apply "limit" to non-table fetches like "select LAST_INSERT_ID"
60 if ( $sql =~ /\bfrom\b/i and defined $limit or defined $offset) {
61 $sql .= " limit $limit" if $limit;
62 $sql .= " offset $offset" if $offset;
63 }
64
65 return ($sql, @params);
66 }
67  
68 ########################################################################
69  
70 ########################################################################
71  
72 =head1 EDITING DATA (SQL DML)
73  
74 =head2 Insert to Add Data
75  
76 =over 4
77  
78 =item do_insert_with_sequence()
79  
80 $sqldb->do_insert_with_sequence( $sequence_name, %sql_clauses ) : $row_count
81  
82 Implemented using _seq_do_insert_postfetch and seq_fetch_current.
83  
84 =item seq_fetch_current
85  
86 $sqldb->seq_fetch_current( ) : $current_value
87  
88 Implemented using MS SQL's "select @@IDENTITY". Note that this
89 doesn't fetch the current sequence value for a given table, since
90 it doesn't respect the table and field arguments, but merely returns
91 the last sequencial value created during this session.
92  
93 =back
94  
95 =cut
96  
97 # $rows = $self->do_insert_with_sequence( $sequence, %clauses );
98 sub do_insert_with_sequence {
99 (shift)->_seq_do_insert_postfetch( @_ )
100 }
101  
102 # $current_id = $sqldb->seq_fetch_current( );
103 sub seq_fetch_current {
104 my ($self, $table, $field) = @_;
105 $self->fetch_one_value(
106 sql => 'select @@IDENTITY AS lastID'
107 );
108 }
109  
110 ########################################################################
111  
112 ########################################################################
113  
114 =head1 DEFINING STRUCTURES (SQL DDL)
115  
116 =head2 Create and Drop Tables
117  
118 =over 4
119  
120 =item dbms_create_column_types()
121  
122 $sqldb->dbms_create_column_types () : %column_type_codes
123  
124 Implemented using MS SQL's blob and int types.
125  
126 =item dbms_create_column_text_long_type
127  
128 $sqldb->dbms_create_column_text_long_type () : $col_type_str
129  
130 Implemented using MS SQL's blob type.
131  
132 =back
133  
134 =cut
135  
136 sub dbms_create_column_types {
137 'sequential' => 'int not null',
138 'binary' => 'blob',
139 }
140  
141 sub dbms_create_column_text_long_type {
142 'blob'
143 }
144  
145 ########################################################################
146  
147 ########################################################################
148  
149 =head1 INTERNAL STATEMENT METHODS (DBI STH)
150  
151 =head2 Statement Handle Lifecycle
152  
153 =over 4
154  
155 =item prepare_execute()
156  
157 After the normal prepare_execute cycle, this also sets the sth's LongReadLen to dbms_longreadlen_bufsize().
158  
159 =item dbms_longreadlen_bufsize()
160  
161 Set to 1_000_000.
162  
163 =back
164  
165 =cut
166  
167 sub dbms_longreadlen_bufsize { 1_000_000 }
168  
169 sub prepare_execute {
170 my $self = shift;
171 my $sth = $self->SUPER::prepare_execute( @_ );
172 $sth->{LongReadLen} = $self->dbms_longreadlen_bufsize;
173 $sth->{LongTruncOk} = 0;
174 $sth;
175 }
176  
177 ########################################################################
178  
179 =head2 recoverable_query_exceptions
180  
181 $sqldb->recoverable_query_exceptions() : @common_error_messages
182  
183 Provides a list of error messages which represent common
184 communication failures or other incidental errors.
185  
186 =cut
187  
188 sub recoverable_query_exceptions {
189 'Communication link failure',
190 'General network error',
191 }
192  
193 ########################################################################
194  
195 =head1 SEE ALSO
196  
197 See L<DBIx::SQLEngine> for the overall interface and developer documentation.
198  
199 See L<DBIx::SQLEngine::Docs::ReadMe> for general information about
200 this distribution, including installation and license information.
201  
202 =cut
203  
204 ########################################################################
205  
206 1;