Switch to C3 mro throughout the ::Storage hierarchy (DBIx::Class brings in MRO::Compa...
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / NoBindVars.pm
1 package DBIx::Class::Storage::DBI::NoBindVars;
2
3 use strict;
4 use warnings;
5
6 use base 'DBIx::Class::Storage::DBI';
7 use mro 'c3';
8
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
21 =head2 connect_info
22
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.
24
25 =cut
26
27 sub connect_info {
28     my $self = shift;
29     my $retval = $self->next::method(@_);
30     $self->disable_sth_caching(1);
31     $retval;
32 }
33
34 =head2 _prep_for_execute
35
36 Manually subs in the values for the usual C<?> placeholders.
37
38 =cut
39
40 sub _prep_for_execute {
41   my $self = shift;
42
43   my ($op, $extra_bind, $ident) = @_;
44
45   my ($sql, $bind) = $self->next::method(@_);
46
47   # stringify args, quote via $dbh, and manually insert
48
49   my @sql_part = split /\?/, $sql;
50   my $new_sql;
51
52   foreach my $bound (@$bind) {
53     my $col = shift @$bound;
54     my $datatype = 'FIXME!!!';
55     foreach my $data (@$bound) {
56         if(ref $data) {
57             $data = ''.$data;
58         }
59         $data = $self->_dbh->quote($data);
60         $new_sql .= shift(@sql_part) . $data;
61     }
62   }
63   $new_sql .= join '', @sql_part;
64
65   return ($new_sql, []);
66 }
67
68 =head1 AUTHORS
69
70 Brandon Black <blblack@gmail.com>
71
72 Trym Skaar <trym@tryms.no>
73
74 =head1 LICENSE
75
76 You may distribute this code under the same terms as Perl itself.
77
78 =cut
79
80 1;