PgLink/Adapter/SybaseASE.pm

filter: Statementstmt 34.2% 49 / 143 Branchbran 0.0% 0 / 40 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 33.3% 9 / 27 Podpod 0.0% 0 / 4 totaltotal 24.2% 58 / 239 CC 30 SCAR 26.4
CC
30
Cov
25%
__ANON__
30.0
__ANON__
30.0
__ANON__
20.0
CRAP 14.0
« PgLink/Adapter.pm ↑ Summary PgLink/Accessor/BaseAccessor.pm »
1 package DBIx::PgLink::Adapter::SybaseASE;
2  
3 # tested on Sybase ASE 12.5 with DBD::Sybase 0.95
4  
5 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use MooseX::Method;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use DBI qw/:sql_types/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 extends 'DBIx::PgLink::Adapter::SQLServer';
12  
13 1 has '+require_parameter_type' => (default=>1);
14  
15 0 ▶override 'quote_identifier' => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
16 0 my ($self, @id) = @_;
17  
18 0 for my $i (@id) {
19 0 ▶ next unless defined $i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $i 0 0 0
20 0 ▶ next if $i =~ /^\w+$/; # quote only when needed
Branch: 1 branch
BranchTrueFalseTotal
if $i =~ /^\w+$/ 0 0 0
21 0 $i =~ s/"/""/g;
22 0 $i = '"' . $i . '"';
23 }
24 0 my $quoted_id = join '.', grep { defined } @id;
25 0 return $quoted_id;
26 1 };
27  
28  
29 # for Reconnect role
30 0 ▶sub is_disconnected {
Subroutine is_disconnected: not called CC=1 SCAR=6.9
Pod undocumented
31 0 my ($self, $exception) = @_;
32 return
33 0 $exception =~ /Net-Library operation terminated due to disconnect/i
34 ;
35 }
36  
37 # ---------------------------- data conversion
38  
39 # PostgreSQL boolean to bit
40 0 ▶sub pg_bool_to_syb_bit {
Subroutine pg_bool_to_syb_bit: not called CC=3 SCAR=24.8
Pod undocumented
41 0 ▶ $_[1] = defined $_[1] ? $_[1] eq 't' ? 1 : 0 : 0; # NULL is not allowed
Branch: 2 branches
BranchTrueFalseTotal
defined $_[1] ? : 0 0 0
$_[1] eq 't' ? : 0 0 0
42 }
43  
44 # Sybase (var)?binary to bytea
45 0 ▶sub syb_binary_to_pg_bytea {
Subroutine syb_binary_to_pg_bytea: not called CC=1 SCAR=6.9
Pod undocumented
46 0 my ($self) = @_;
47 0 $_[1] =~ s/^0x//;
48 0 $_[1] = pack("H*", $_[1]);
49 0 $self->to_pg_bytea($_[1]);
50 }
51  
52  
53 # catalog functions very picky about input
54  
55 0 ▶around 'table_info' => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
56 0 my ($next, $self, $catalog, $schema, $table, $type) = @_;
57  
58 # catalog must be current database name
59 0 ▶ if (!$catalog || $catalog eq '%') {
Branch: 1 branch
BranchTrueFalseTotal
if (not $catalog or $catalog eq "%") 0 0 0
Condition0%0/3
not $catalog or $catalog eq "%"
l!l&&r!l&&!r
000
MC/DC0%0/2
not $catalog or $catalog eq "%"
not $catalog $catalog eq "%"
Truth table0%0/3
not(A) or B
A= not $catalogB= $catalog eq "%"
ABresult
1X1
011
000
60 0 $catalog = $self->current_database();
61 }
62 # type entries must be quoted
63 0 ▶ if ($type !~ /'/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type =~ /'/) 0 0 0
64 0 $type = join ',', map { "'$_'" } split /,/, $type;
65 }
66 0 $next->($self, $catalog, $schema, $table, $type);
67 # cannot fix column names here
68 1 };
69  
70  
71 0 ▶around 'column_info' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
72 0 my ($next, $self, $catalog, $schema, $table, $column) = @_;
73  
74 # catalog must be current database name
75 0 ▶ if (!$catalog || $catalog eq '%') {
Branch: 1 branch
BranchTrueFalseTotal
if (not $catalog or $catalog eq "%") 0 0 0
Condition0%0/3
not $catalog or $catalog eq "%"
l!l&&r!l&&!r
000
MC/DC0%0/2
not $catalog or $catalog eq "%"
not $catalog $catalog eq "%"
Truth table0%0/3
not(A) or B
A= not $catalogB= $catalog eq "%"
ABresult
1X1
011
000
76 0 $catalog = $self->current_database();
77 }
78 0 $next->($self, $catalog, $schema, $table, $column);
79 1 };
80  
81  
82 0 ▶sub _uppercase_hashref_keys {
Subroutine _uppercase_hashref_keys: not called CC=2 SCAR=17.9
83 0 my $href = shift;
84 0 my @keys = keys %{$href};
85 0 for my $key (@keys) {
86 0 $href->{uc $key} = delete $href->{$key};
87 }
88 }
89  
90  
91 0 ▶around 'expand_table_info' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
92 0 my ($next, $self, $table) = @_;
93  
94 0 _uppercase_hashref_keys($table);
95  
96 # bug: DBD::Sybase v0.95 return non-standard field name
97 0 ▶ $table->{TABLE_CAT} ||= $table->{TABLE_QUALIFIER};
Condition0%0/3
$table->{"TABLE_CAT"} ||= $table->{"TABLE_QUALIFIER"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$table->{"TABLE_CAT"} ||= $table->{"TABLE_QUALIFIER"}
$table->{"TABLE_CAT"} $table->{"TABLE_QUALIFIER"}
Truth table0%0/3
A ||= B
A= $table->{"TABLE_CAT"}B= $table->{"TABLE_QUALIFIER"}
ABresult
1X1
011
000
98 0 ▶ $table->{TABLE_SCHEM} ||= $table->{TABLE_OWNER};
Condition0%0/3
$table->{"TABLE_SCHEM"} ||= $table->{"TABLE_OWNER"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$table->{"TABLE_SCHEM"} ||= $table->{"TABLE_OWNER"}
$table->{"TABLE_SCHEM"} $table->{"TABLE_OWNER"}
Truth table0%0/3
A ||= B
A= $table->{"TABLE_SCHEM"}B= $table->{"TABLE_OWNER"}
ABresult
1X1
011
000
99  
100 0 $next->($self, $table);
101 1 };
102  
103  
104 0 ▶around 'expand_column_info', 'expand_primary_key_info' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
105 0 my ($next, $self, $info) = @_;
106  
107 0 _uppercase_hashref_keys($info);
108  
109 0 $next->($self, $info);
110 1 };
111  
112  
113 # DBD::Sybase has problem with placeholders in prepared SP call
114 1 for my $func (qw/
115 prepare prepare_cached
116 /) {
117 0 ▶ around $func => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
118 0 my $next = shift;
119 0 my $self = shift;
120 0 my $statement = shift;
121 0 my $attr = shift;
122  
123 0 ▶ if ($statement =~ /^EXEC.*\?/i && $self->dbh->{Driver}->{Name} eq 'Sybase') {
Branch: 1 branch
BranchTrueFalseTotal
if ($statement =~ /^EXEC.*\?/i and $self->dbh->{'Driver'}{'Name'} eq 'Sybase') { } 0 0 0
Condition0%0/3
$statement =~ /^EXEC.*\?/i and $self->dbh->{"Driver"}{"Name"} eq "Sybase"
!ll&&!rl&&r
000
MC/DC0%0/2
$statement =~ /^EXEC.*\?/i and $self->dbh->{"Driver"}{"Name"} eq "Sybase"
$statement =~ /^EXEC.*\?/i $self->dbh->{"Driver"}{"Name"} eq "Sybase"
Truth table0%0/3
A and B
A= $statement =~ /^EXEC.*\?/iB= $self->dbh->{"Driver"}{"Name"} eq "Sybase"
ABresult
0X0
100
111
124 return $self->new_statement(
125 class => 'DBIx::PgLink::Adapter::SybaseASE::PreparedProcedure',
126 statement => $statement,
127 parent => $self,
128 method => $func,
129 0 ▶ defined $attr ? %{$attr} : (),
Branch: 1 branch
BranchTrueFalseTotal
defined $attr ? : 0 0 0
130 );
131 } else {
132 0 return $next->($self, $statement, $attr);
133 }
134 2 };
135 }
136  
137 has 'quote_literal_types' => ( # initialize once for connection
138 is=>'ro', isa=>'HashRef', lazy=>1,
139 0 ▶ default=>sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
140 return {
141 0 SQL_BINARY() => undef,
142 SQL_BLOB() => undef,
143 SQL_CHAR() => undef,
144 SQL_DATE() => undef,
145 SQL_VARBINARY() => undef,
146 SQL_VARCHAR() => undef,
147 } },
148 1 );
149  
150  
151  
152  
153 0 ▶around 'routine_info_arrayref' => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
154 0 my ($next, $self, $catalog, $schema, $routine, $type) = @_;
155  
156 # TODO: parse $type and add Java function support (very low priority)
157 0 ▶ return $next->($self, $catalog, $schema, $routine, $type) unless $type =~ /PROCEDURE/;
Branch: 1 branch
BranchTrueFalseTotal
unless $type =~ /PROCEDURE/ 0 0 0
158  
159 0 my @result = ();
160  
161 0 my $full_proc_name = $self->quote_identifier(
162 $catalog,
163 'dbo',
164 'sp_stored_procedures'
165 );
166 0 my $sth = $self->prepare("exec $full_proc_name ?, ?, ?");
167 0 $sth->execute( # name in reverse order
168 $routine,
169 $schema,
170 $catalog,
171 );
172  
173 0 ▶ while (my $sp = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sp = $sth->fetchrow_hashref) 0 0 0
174 0 my $proc_name = $sp->{procedure_name};
175 0 $proc_name =~ s/;\d+$//; # obsolete procedure group number
176 my $i = {
177 SPECIFIC_CATALOG => $sp->{procedure_qualifier},
178 SPECIFIC_SCHEMA => $sp->{procedure_owner},
179 SPECIFIC_NAME => $proc_name,
180 ROUTINE_CATALOG => $sp->{procedure_qualifier},
181 ROUTINE_SCHEMA => $sp->{procedure_owner},
182 0 ROUTINE_NAME => $proc_name,
183 ROUTINE_TYPE => 'PROCEDURE',
184 DATA_TYPE => undef,
185 };
186 0 ▶ $self->expand_routine_info($i)
Branch: 1 branch
BranchTrueFalseTotal
$self->expand_routine_info($i) and push @result, $i 0 0 0
187 and push @result, $i;
188 }
189 0 $sth->finish;
190  
191 0 return \@result;
192  
193 1 };
194  
195  
196 0 ▶around 'expand_routine_argument_info' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
197 0 my ($next, $self, $arg) = @_;
198  
199 0 _uppercase_hashref_keys($arg);
200  
201 0 $next->($self, $arg);
202 1 };
203  
204  
205 0 ▶sub dummy_procedure_call_arguments {
Subroutine dummy_procedure_call_arguments: not called CC=2 SCAR=17.9
Pod undocumented
206 0 my ($self, $routine_info) = @_;
207 # 'bit' type does not allow NULL
208 return map {
209 0 ▶ $_->{DATA_TYPE} == SQL_BIT ? '0' : 'NULL'
Branch: 1 branch
BranchTrueFalseTotal
$_->{'DATA_TYPE'} == &SQL_BIT() ? : 0 0 0
210 0 } @{$self->routine_argument_info_arrayref($routine_info)};
211 }
212  
213  
214 1 1;
215  
216  
217 # emulate prepared statement for DBD::Sybase
218  
219 package DBIx::PgLink::Adapter::SybaseASE::PreparedProcedure;
220  
221 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
222 1 ▶use DBIx::PgLink::Adapter;
Subroutine BEGIN: called CC=1 SCAR=0.0
223 1 ▶use DBIx::PgLink::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
224 1 ▶use DBI qw/:sql_types/;
Subroutine BEGIN: called CC=1 SCAR=0.0
225  
226 1 extends 'DBIx::PgLink::Adapter::st';
227  
228 1 has '+sth' => ( required=>0 );
229  
230 1 has 'statement' => ( is=>'ro', isa=>'Str', required=>1 );
231  
232 1 has 'method' => ( is=>'ro', isa=>'Str', required=>1 );
233  
234 0 ▶has 'param_values' => ( is=>'rw', isa=>'ArrayRef', default=>sub { [] } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
235  
236 0 ▶around 'finish' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
237 0 my $next = shift;
238 0 my $self = shift;
239  
240 0 $self->param_values( [] );
241 0 ▶ $self->sth->finish if $self->sth;
Branch: 1 branch
BranchTrueFalseTotal
if $self->sth 0 0 0
242 1 };
243  
244  
245 0 ▶around 'bind_param' => sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
246 0 my $next = shift;
247 0 my ($self, $p_num, $bind_value, $attr) = @_;
248  
249 0 ▶ my $type = ref $attr eq 'HASH' ? $attr->{TYPE} : $attr;
Branch: 1 branch
BranchTrueFalseTotal
ref $attr eq 'HASH' ? : 0 0 0
250  
251 0 ▶ if (exists $self->parent->quote_literal_types->{$type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->parent->quote_literal_types->{$type}) 0 0 0
252 0 $bind_value = $self->parent->quote($bind_value);
253 }
254 0 $self->param_values->[$p_num-1] = $bind_value;
255 0 ▶ trace_msg('INFO', "Bind $p_num " . (defined $bind_value ? $bind_value : 'NULL'))
Branch: 2 branches
BranchTrueFalseTotal
if &trace_level() >= 4 0 0 0
defined $bind_value ? : 0 0 0
256 if trace_level >= 4;
257 0 return 1;
258 1 };
259  
260  
261 0 ▶around 'execute' => sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
262 0 my $next = shift;
263 0 my $self = shift;
264  
265 0 for my $i (0..$#_) {
266 0 $self->bind_param($i+1, $_[$i], SQL_VARCHAR);
267 }
268  
269 # naive replacement of ?-placeholders by literal value
270 0 my $query = $self->statement;
271 0 for my $p (@{$self->param_values}) {
272 0 $query =~ s/\?/$p/;
273 }
274  
275 0 ▶ $self->sth->finish if $self->sth;
Branch: 1 branch
BranchTrueFalseTotal
if $self->sth 0 0 0
276 0 ▶ my $sth = $self->method eq 'prepare_cached'
Branch: 1 branch
BranchTrueFalseTotal
$self->method eq 'prepare_cached' ? : 0 0 0
277 ? $self->parent->dbh->prepare_cached($query)
278 : $self->parent->dbh->prepare($query);
279 0 $self->{sth} = $sth;
280 0 return $sth->execute;
281 1 };
282  
283  
284 1 1;
« PgLink/Adapter.pm ↑ Summary PgLink/Accessor/BaseAccessor.pm »