Clarify sybase/nobindvars problem (should have never merged in the 1st place)
[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
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
20 =head2 connect_info
21
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.
23
24 =cut
25
26 sub connect_info {
27     my $self = shift;
28     my $retval = $self->next::method(@_);
29     $self->disable_sth_caching(1);
30     $retval;
31 }
32
33 =head2 _prep_for_execute
34
35 Manually subs in the values for the usual C<?> placeholders.
36
37 =cut
38
39 sub _prep_for_execute {
40   my $self = shift;
41
42   my ($op, $extra_bind, $ident) = @_;
43
44   my ($sql, $bind) = $self->next::method(@_);
45
46   # stringify args, quote via $dbh, and manually insert
47
48   my @sql_part = split /\?/, $sql;
49   my $new_sql;
50
51   foreach my $bound (@$bind) {
52     my $col = shift @$bound;
53     my $datatype = 'FIXME!!!';
54     foreach my $data (@$bound) {
55         if(ref $data) {
56             $data = ''.$data;
57         }
58         $data = $self->_dbh->quote($data) if $self->should_quote_data_type($datatype, $data);
59         $new_sql .= shift(@sql_part) . $data;
60     }
61   }
62   $new_sql .= join '', @sql_part;
63
64   return ($new_sql);
65 }
66
67 =head2 should_quote_data_type
68
69 This method is called by L</_prep_for_execute> for every column in
70 order to determine if its value should be quoted or not. The arguments
71 are the current column data type and the actual bind value. The return
72 value is interpreted as: true - do quote, false - do not quote. You should
73 override this in you Storage::DBI::<database> subclass, if your RDBMS
74 does not like quotes around certain datatypes (e.g. Sybase and integer
75 columns). The default method always returns true (do quote).
76
77  WARNING!!!
78
79  Always validate that the bind-value is valid for the current datatype.
80  Otherwise you may very well open the door to SQL injection attacks.
81
82 =cut
83
84 sub should_quote_data_type { 1 }
85
86 =head1 AUTHORS
87
88 Brandon Black <blblack@gmail.com>
89
90 Trym Skaar <trym@tryms.no>
91
92 =head1 LICENSE
93
94 You may distribute this code under the same terms as Perl itself.
95
96 =cut
97
98 1;