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 ($sql, $bind) = $self->next::method(@_);
45 # stringify bind args, quote via $dbh, and manually insert
46 #my ($op, $ident, $args) = @_;
49 my @sql_part = split /\?/, $sql;
53 my $data = (ref $_->[1]) ? "$_->[1]" : $_->[1]; # always stringify, array types are currently not supported
55 my $datatype = $_->[0]{sqlt_datatype};
57 $data = $self->_prep_interpolated_value($datatype, $data)
60 $data = $self->_get_dbh->quote($data)
61 unless ($datatype and $self->interpolate_unquoted($datatype, $data) );
63 $new_sql .= shift(@sql_part) . $data;
66 $new_sql .= join '', @sql_part;
68 return ($new_sql, []);
71 =head2 interpolate_unquoted
73 This method is called by L</_prep_for_execute> for every column in
74 order to determine if its value should be quoted or not. The arguments
75 are the current column data type and the actual bind value. The return
76 value is interpreted as: true - do not quote, false - do quote. You should
77 override this in you Storage::DBI::<database> subclass, if your RDBMS
78 does not like quotes around certain datatypes (e.g. Sybase and integer
79 columns). The default method always returns false (do quote).
83 Always validate that the bind-value is valid for the current datatype.
84 Otherwise you may very well open the door to SQL injection attacks.
88 sub interpolate_unquoted {
89 #my ($self, $datatype, $value) = @_;
93 =head2 _prep_interpolated_value
95 Given a datatype and the value to be inserted directly into a SQL query, returns
96 the necessary string to represent that value (by e.g. adding a '$' sign)
100 sub _prep_interpolated_value {
101 #my ($self, $datatype, $value) = @_;
107 See L<DBIx::Class/CONTRIBUTORS>
111 You may distribute this code under the same terms as Perl itself.