Commit | Line | Data |
3885cff6 |
1 | package DBIx::Class::Storage::DBI::NoBindVars; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use base 'DBIx::Class::Storage::DBI'; |
7 | |
b43345f2 |
8 | =head1 NAME |
9 | |
10 | DBIx::Class::Storage::DBI::NoBindVars - Sometime DBDs have poor to no support for bind variables |
11 | |
12 | =head1 DESCRIPTION |
13 | |
14 | This class allows queries to work when the DBD or underlying library does not |
15 | support the usual C<?> placeholders, or at least doesn't support them very |
16 | well, as is the case with L<DBD::Sybase> |
17 | |
18 | =head1 METHODS |
19 | |
b33697ef |
20 | =head2 connect_info |
b43345f2 |
21 | |
b33697ef |
22 | We can't cache very effectively without bind variables, so force the C<disable_sth_caching> setting to be turned on when the connect info is set. |
b43345f2 |
23 | |
24 | =cut |
25 | |
b33697ef |
26 | sub connect_info { |
27 | my $self = shift; |
d944c5ae |
28 | my $retval = $self->next::method(@_); |
b33697ef |
29 | $self->disable_sth_caching(1); |
30 | $retval; |
b43345f2 |
31 | } |
32 | |
d5130dd2 |
33 | =head2 _prep_for_execute |
b43345f2 |
34 | |
d5130dd2 |
35 | Manually subs in the values for the usual C<?> placeholders. |
b43345f2 |
36 | |
37 | =cut |
38 | |
d5130dd2 |
39 | sub _prep_for_execute { |
40 | my $self = shift; |
d944c5ae |
41 | my ($sql, $bind) = $self->next::method(@_); |
42 | |
43 | # stringify args, quote via $dbh, and manually insert |
44 | |
b4474f31 |
45 | my @sql_part = split /\?/, $sql; |
46 | my $new_sql; |
47 | |
d944c5ae |
48 | foreach my $bound (@$bind) { |
49 | shift @$bound; |
50 | foreach my $data (@$bound) { |
51 | if(ref $data) { |
52 | $data = ''.$data; |
53 | } |
b4474f31 |
54 | $new_sql .= shift(@sql_part) . $self->_dbh->quote($data); |
d944c5ae |
55 | } |
56 | } |
b4474f31 |
57 | $new_sql .= join '', @sql_part; |
d5130dd2 |
58 | |
b4474f31 |
59 | return ($new_sql); |
3885cff6 |
60 | } |
61 | |
3885cff6 |
62 | =head1 AUTHORS |
63 | |
64 | Brandon Black <blblack@gmail.com> |
b43345f2 |
65 | |
7762b22c |
66 | Trym Skaar <trym@tryms.no> |
3885cff6 |
67 | |
68 | =head1 LICENSE |
69 | |
70 | You may distribute this code under the same terms as Perl itself. |
71 | |
72 | =cut |
b43345f2 |
73 | |
74 | 1; |