Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix quoting in mysql
the old mechanism did not consider undefined values NULL, and failed
for empty strings and for stuff that looked vaguely like numbers, but were
not well-formed numbers
  • Loading branch information
moritz committed Mar 24, 2013
1 parent 60438cf commit 3790014
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
11 changes: 8 additions & 3 deletions lib/DBDish/mysql.pm6
Expand Up @@ -145,11 +145,16 @@ class DBDish::mysql::StatementHandle does DBDish::StatementHandle {
my $statement = $!statement;
while @params.elems>0 and $statement.index('?')>=0 {
my $param = @params.shift;
if $param ~~ /<-[0..9.]>/ {
$statement .= subst("?", self.quote($param.Str)); # quote non numerics
if $param.defined {
if $param ~~ Real {
$statement .= subst("?", $param.Str);
}
else {
$statement .= subst("?", self.quote($param.Str));
}
}
else {
$statement .= subst("?", $param); # do not quote numbers
$statement .= subst("?", 'NULL'); # do not quote numbers
}
}
# warn "in DBDish::mysql::StatementHandle.execute statement=$statement";
Expand Down
6 changes: 3 additions & 3 deletions t/10-mysql.t
Expand Up @@ -39,9 +39,9 @@ use DBIish;
my $mdriver = 'mysql';
my $host = 'localhost';
my $port = 3306;
my $database = 'zavolaj';
my $test_user = 'testuser';
my $test_password = 'testpass';
my $database = 'moritz4';
my $test_user = 'moritz';
my $test_password = 'aeNohh4a';
my $table = 't1';

#-----------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions t/25-mysql-common.t
Expand Up @@ -8,9 +8,9 @@ my $*mdriver = 'mysql';
my %*opts = ().hash;
%*opts<host> = 'localhost';
%*opts<port> = 3306;
%*opts<database> = 'zavolaj';
%*opts<user> = 'testuser';
%*opts<password> = 'testpass';
%*opts<database> = 'moritz4';
%*opts<user> = 'moritz';
%*opts<password> = 'aeNohh4a';

# Detect and report possible errors from eval of the common test script
warn $! if "ok 99-common.pl6" ne eval slurp 't/99-common.pl6';

0 comments on commit 3790014

Please sign in to comment.