DBIx/Class/Storage/DBI/AutoCast.pm

filter: Statementstmt 92.3% 24 / 26 Branchbran 100% 4 / 4 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 83.3% 5 / 6 Podpod 100% 1 / 1 totaltotal 88.1% 37 / 42 CC 5 SCAR 11.3
CC
5
Cov
91%
_prep_for_execute
5.0
connect_call_set_auto_cast
2.0
BEGIN
1.0
CRAP 3.1
« DBIx/Class/CDBICompat/ReadOnly.pm ↑ Summary DBIx/Class/ResultSet/Pager.pm »
1 package DBIx::Class::Storage::DBI::AutoCast;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use base qw/DBIx::Class::Storage::DBI/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 __PACKAGE__->mk_group_accessors('simple' => 'auto_cast' );
10  
11 =head1 NAME
12  
13 DBIx::Class::Storage::DBI::AutoCast - Storage component for RDBMS requiring explicit placeholder typing
14  
15 =head1 SYNOPSIS
16  
17 $schema->storage->auto_cast(1);
18  
19 =head1 DESCRIPTION
20  
21 In some combinations of RDBMS and DBD drivers (e.g. FreeTDS and Sybase)
22 statements with values bound to columns or conditions that are not strings will
23 throw implicit type conversion errors.
24  
25 As long as a column L<data_type|DBIx::Class::ResultSource/add_columns> is
26 defined and resolves to a base RDBMS native type via
27 L<_native_data_type|DBIx::Class::Storage::DBI/_native_data_type> as
28 defined in your Storage driver, the placeholder for this column will be
29 converted to:
30  
31 CAST(? as $mapped_type)
32  
33 This option can also be enabled in
34 L<connect_info|DBIx::Class::Storage::DBI/connect_info> as:
35  
36 on_connect_call => ['set_auto_cast']
37  
38 =cut
39  
40 25 ▶sub _prep_for_execute {
Subroutine _prep_for_execute: called CC=5 SCAR=16.1
41 25 my $self = shift;
42  
43 25 my ($sql, $bind) = $self->next::method (@_);
44  
45 # If we're using ::NoBindVars, there are no binds by this point so this code
46 # gets skipped.
47 25 ▶ if ($self->auto_cast && @$bind) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->auto_cast and @$bind) 1 24 25
Condition66%2/3
$self->auto_cast and @$bind
!ll&&!rl&&r
2401
MC/DC50%1/2
$self->auto_cast and @$bind
$self->auto_cast @$bind
Truth table66%2/3
A and B
A= $self->auto_castB= @$bind
ABresult
0X0
100
111
48 1 my $new_sql;
49 1 my @sql_part = split /\?/, $sql, scalar @$bind + 1;
50 1 for (@$bind) {
51 4 my $cast_type = $self->_native_data_type($_->[0]{sqlt_datatype});
52 4 ▶ $new_sql .= shift(@sql_part) . ($cast_type ? "CAST(? AS $cast_type)" : '?');
Branch: 1 branch
BranchTrueFalseTotal
$cast_type ? : 3 1 4
53 }
54 1 $sql = $new_sql . shift @sql_part;
55 }
56  
57 25 return ($sql, $bind);
58 }
59  
60 =head2 connect_call_set_auto_cast
61  
62 Executes:
63  
64 $schema->storage->auto_cast(1);
65  
66 on connection.
67  
68 Used as:
69  
70 on_connect_call => ['set_auto_cast']
71  
72 in L<connect_info|DBIx::Class::Storage::DBI/connect_info>.
73  
74 =cut
75  
76 0 ▶sub connect_call_set_auto_cast {
Subroutine connect_call_set_auto_cast: not called CC=1 SCAR=6.9
Pod documented
77 0 my $self = shift;
78 0 $self->auto_cast(1);
79 }
80  
81 =head1 FURTHER QUESTIONS?
82  
83 Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
84  
85 =head1 COPYRIGHT AND LICENSE
86  
87 This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
88 by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
89 redistribute it and/or modify it under the same terms as the
90 L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
91  
92 =cut
93  
94 4 1;
« DBIx/Class/CDBICompat/ReadOnly.pm ↑ Summary DBIx/Class/ResultSet/Pager.pm »