Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[mysql] do not screw up when there are question marks in the data
  • Loading branch information
moritz committed Mar 24, 2013
1 parent 3790014 commit 7903d63
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/DBDish/mysql.pm6
Expand Up @@ -142,22 +142,26 @@ class DBDish::mysql::StatementHandle does DBDish::StatementHandle {

method execute(*@params is copy) {
# warn "in DBDish::mysql::StatementHandle.execute()";
my $statement = $!statement;
while @params.elems>0 and $statement.index('?')>=0 {
my $statement = '';
my @chunks = $!statement.split('?', @params + 1);
my $last-chunk = @chunks.pop;
for @chunks {
$statement ~= $_;
my $param = @params.shift;
if $param.defined {
if $param ~~ Real {
$statement .= subst("?", $param.Str);
$statement ~= $param
}
else {
$statement .= subst("?", self.quote($param.Str));
$statement ~= self.quote($param.Str);
}
}
else {
$statement .= subst("?", 'NULL'); # do not quote numbers
$statement ~= 'NULL';
}
}
# warn "in DBDish::mysql::StatementHandle.execute statement=$statement";
$statement ~= $last-chunk;
# note "in DBDish::mysql::StatementHandle.execute statement=$statement";
$!result_set = Mu;
my $status = mysql_query( $!mysql_client, $statement ); # 0 means OK
$.mysql_warning_count = mysql_warning_count( $!mysql_client );
Expand Down

0 comments on commit 7903d63

Please sign in to comment.