1 package DBIx::Class::Storage::DBI::NoBindVars;
6 use base 'DBIx::Class::Storage::DBI';
11 DBIx::Class::Storage::DBI::NoBindVars - Sometime DBDs have poor to no support for bind variables
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>
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.
29 my $retval = $self->next::method(@_);
30 $self->disable_sth_caching(1);
34 =head2 _prep_for_execute
36 Manually subs in the values for the usual C<?> placeholders.
40 sub _prep_for_execute {
43 my ($op, $extra_bind, $ident, $args) = @_;
45 my ($sql, $bind) = $self->next::method(@_);
47 # stringify args, quote via $dbh, and manually insert
49 my @sql_part = split /\?/, $sql;
52 my ($alias2src, $rs_alias) = $self->_resolve_ident_sources($ident);
54 foreach my $bound (@$bind) {
55 my $col = shift @$bound;
57 my $name_sep = $self->_sql_maker_opts->{name_sep} || '.';
59 $col =~ s/^([^\Q${name_sep}\E]*)\Q${name_sep}\E//;
60 my $alias = $1 || $rs_alias;
62 my $rsrc = $alias2src->{$alias};
64 my $datatype = $rsrc && $rsrc->column_info($col)->{data_type};
66 foreach my $data (@$bound) {
67 $data = ''.$data if ref $data;
69 $data = $self->_dbh->quote($data)
70 if $self->should_quote_value($datatype, $data);
72 $new_sql .= shift(@sql_part) . $data;
75 $new_sql .= join '', @sql_part;
77 return ($new_sql, []);
80 =head2 should_quote_value
82 This method is called by L</_prep_for_execute> for every column in
83 order to determine if its value should be quoted or not. The arguments
84 are the current column data type and the actual bind value. The return
85 value is interpreted as: true - do quote, false - do not quote. You should
86 override this in you Storage::DBI::<database> subclass, if your RDBMS
87 does not like quotes around certain datatypes (e.g. Sybase and integer
88 columns). The default method always returns true (do quote).
92 Always validate that the bind-value is valid for the current datatype.
93 Otherwise you may very well open the door to SQL injection attacks.
97 sub should_quote_value { 1 }
101 Brandon Black <blblack@gmail.com>
103 Trym Skaar <trym@tryms.no>
107 You may distribute this code under the same terms as Perl itself.