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'; |
2ad62d97 |
7 | use mro 'c3'; |
3885cff6 |
8 | |
b43345f2 |
9 | =head1 NAME |
10 | |
11 | DBIx::Class::Storage::DBI::NoBindVars - Sometime DBDs have poor to no support for bind variables |
12 | |
13 | =head1 DESCRIPTION |
14 | |
15 | This class allows queries to work when the DBD or underlying library does not |
16 | support the usual C<?> placeholders, or at least doesn't support them very |
17 | well, as is the case with L<DBD::Sybase> |
18 | |
19 | =head1 METHODS |
20 | |
b33697ef |
21 | =head2 connect_info |
b43345f2 |
22 | |
b33697ef |
23 | 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 |
24 | |
25 | =cut |
26 | |
b33697ef |
27 | sub connect_info { |
28 | my $self = shift; |
d944c5ae |
29 | my $retval = $self->next::method(@_); |
b33697ef |
30 | $self->disable_sth_caching(1); |
31 | $retval; |
b43345f2 |
32 | } |
33 | |
d5130dd2 |
34 | =head2 _prep_for_execute |
b43345f2 |
35 | |
d5130dd2 |
36 | Manually subs in the values for the usual C<?> placeholders. |
b43345f2 |
37 | |
38 | =cut |
39 | |
d5130dd2 |
40 | sub _prep_for_execute { |
41 | my $self = shift; |
b50a5275 |
42 | |
43 | my ($op, $extra_bind, $ident) = @_; |
44 | |
d944c5ae |
45 | my ($sql, $bind) = $self->next::method(@_); |
46 | |
47 | # stringify args, quote via $dbh, and manually insert |
48 | |
b4474f31 |
49 | my @sql_part = split /\?/, $sql; |
50 | my $new_sql; |
51 | |
d944c5ae |
52 | foreach my $bound (@$bind) { |
b50a5275 |
53 | my $col = shift @$bound; |
5432c6ae |
54 | my $datatype = 'FIXME!!!'; |
d944c5ae |
55 | foreach my $data (@$bound) { |
56 | if(ref $data) { |
57 | $data = ''.$data; |
58 | } |
35e3ee0e |
59 | $data = $self->_dbh->quote($data); |
b50a5275 |
60 | $new_sql .= shift(@sql_part) . $data; |
d944c5ae |
61 | } |
62 | } |
b4474f31 |
63 | $new_sql .= join '', @sql_part; |
d5130dd2 |
64 | |
01c04b1b |
65 | return ($new_sql, []); |
3885cff6 |
66 | } |
67 | |
3885cff6 |
68 | =head1 AUTHORS |
69 | |
70 | Brandon Black <blblack@gmail.com> |
b43345f2 |
71 | |
7762b22c |
72 | Trym Skaar <trym@tryms.no> |
3885cff6 |
73 | |
74 | =head1 LICENSE |
75 | |
76 | You may distribute this code under the same terms as Perl itself. |
77 | |
78 | =cut |
b43345f2 |
79 | |
80 | 1; |