SQLEngine/Driver/Trait/NoPlaceholders.pm untested

filter: Statementstmt 0.0% 0 / 23 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 37 CC 2 SCAR 11.5
CC
2
Cov
0%
prepare_execute
6.0
import
2.0
dbms_placeholders_unsupported
2.0
CRAP 3.1
1 =head1 NAME
2  
3 DBIx::SQLEngine::Driver::Trait::NoPlaceholders - For drivers without placeholders
4  
5 =head1 SYNOPSIS
6  
7 # Classes can import this behavior if they don't have joins using "on"
8 use DBIx::SQLEngine::Driver::Trait::NoPlaceholders ':all';
9
10 # Queries which would typically use placeholders need special treatment
11 $hash_ary = $sqldb->fetch_select(
12 table => 'students', where => { 'status'=>'minor' },
13 );
14  
15  
16 =head1 DESCRIPTION
17  
18 This package supports drivers or database servers which do support the use of "?"-style placeholders in queries.
19  
20 This is a problem for Linux users of DBD::Sybase connecting to MS SQL Servers on Windows.
21  
22 This package attempts to substitute the placeholders into the query before executing it.
23  
24 =head2 About Driver Traits
25  
26 You do not need to use this package directly; it is used internally by those driver subclasses which need it.
27  
28 For more information about Driver Traits, see L<DBIx::SQLEngine::Driver/"About Driver Traits">.
29  
30 =cut
31  
32 ########################################################################
33  
34 package DBIx::SQLEngine::Driver::Trait::NoPlaceholders;
35  
36 use Exporter;
37 sub import { goto &Exporter::import }
38 @EXPORT_OK = qw(
39 prepare_execute
40 );
41 %EXPORT_TAGS = ( all => \@EXPORT_OK );
42  
43 use strict;
44 use Carp;
45  
46 ########################################################################
47  
48 =head1 REFERENCE
49  
50 =cut
51  
52 ########################################################################
53  
54 =head2 Database Capability Information
55  
56 =over 4
57  
58 =item dbms_placeholders_unsupported()
59  
60 $sqldb->dbms_placeholders_unsupported() : 1
61  
62 Capability Limitation: This driver does not support "?"-style placehoders.
63  
64 =back
65  
66 =cut
67  
68 sub dbms_placeholders_unsupported { 1 }
69  
70 ########################################################################
71  
72 =head2 Statement Handle Lifecycle
73  
74 =over 4
75  
76 =item prepare_execute()
77  
78 $sqldb->prepare_execute ($sql, @params) : $sth
79  
80 Prepare, bind, and execute a SQL statement to create a DBI statement handle.
81  
82 Uses the DBI prepare_cached() and execute() methods.
83  
84 Instead of using bind_params, attempts to subtitute them into the statement using the DBI quote() method.
85  
86 To Do: This could benefit from a much wider range of tests to confirm that the substitution is being applied as expected.
87  
88 To Do: Examine the optional type information that can be passed with parameters. This is currently ignored, but could be used to differentiate between string types that needed to be quoted and those numeric types that don't.
89  
90 =back
91  
92 =cut
93  
94 # $sth = $self->prepare_execute($sql);
95 # $sth = $self->prepare_execute($sql, @params);
96 sub prepare_execute {
97 my ($self, $sql, @params) = @_;
98
99 my @values;
100 for my $param_no ( 0 .. $#params ) {
101 my $param_v = $params[$param_no];
102 my @param_v = ( ref($param_v) eq 'ARRAY' ) ? @$param_v : $param_v;
103 $values[ $param_no+1 ] = $param_v[0];
104 }
105
106 $sql =~ s{\?}{ scalar(@values) or croak "not enough parameters";
107 $self->quote( shift @values ) }geo;
108 ! scalar(@values) or croak "too many parameters";
109
110 my $sth = $self->prepare_cached($sql);
111 $self->{_last_sth_execute} = $sth->execute();
112
113 return $sth;
114 }
115  
116 ########################################################################
117  
118 =head1 SEE ALSO
119  
120 See L<DBIx::SQLEngine> for the overall interface and developer documentation.
121  
122 See L<DBIx::SQLEngine::Docs::ReadMe> for general information about
123 this distribution, including installation and license information.
124  
125 =cut
126  
127 ########################################################################
128  
129 1;
130