=item C<$pattern> - the regular expression to search for (scalar)
+=item C<$nocheck> - true if the pattern should not be tested; false otherwise (boolean)
+
+=item C<$real_pattern> - the real regular expression to search for.
+This argument is used when C<$pattern> is a placeholder ('?').
+
=back
=item B<Returns>
=item B<Params>
-=over
-
-=item C<$expr> - SQL expression for the text to be searched (scalar)
-
-=item C<$pattern> - the regular expression to search for (scalar)
-
-=back
+Same as L</sql_regexp>.
=item B<Returns>
}
sub sql_regexp {
- my ($self, $expr, $pattern, $nocheck) = @_;
+ my ($self, $expr, $pattern, $nocheck, $real_pattern) = @_;
+ $real_pattern ||= $pattern;
- $self->bz_check_regexp($pattern) if !$nocheck;
+ $self->bz_check_regexp($real_pattern) if !$nocheck;
return "$expr REGEXP $pattern";
}
sub sql_not_regexp {
- my ($self, $expr, $pattern, $nocheck) = @_;
+ my ($self, $expr, $pattern, $nocheck, $real_pattern) = @_;
+ $real_pattern ||= $pattern;
- $self->bz_check_regexp($pattern) if !$nocheck;
+ $self->bz_check_regexp($real_pattern) if !$nocheck;
return "$expr NOT REGEXP $pattern";
}
my ($self, $pattern) = @_;
eval { $self->do("SELECT 1 FROM DUAL WHERE "
- . $self->sql_regexp($self->quote("a"), $self->quote($pattern), 1)) };
+ . $self->sql_regexp($self->quote("a"), $pattern, 1)) };
$@ && ThrowUserError('illegal_regexp',
{ value => $pattern, dberror => $self->errstr });
}
sub sql_regexp {
- my ($self, $expr, $pattern, $nocheck) = @_;
+ my ($self, $expr, $pattern, $nocheck, $real_pattern) = @_;
+ $real_pattern ||= $pattern;
- $self->bz_check_regexp($pattern) if !$nocheck;
+ $self->bz_check_regexp($real_pattern) if !$nocheck;
return "REGEXP_LIKE($expr, $pattern)";
}
sub sql_not_regexp {
- my ($self, $expr, $pattern, $nocheck) = @_;
+ my ($self, $expr, $pattern, $nocheck, $real_pattern) = @_;
+ $real_pattern ||= $pattern;
- $self->bz_check_regexp($pattern) if !$nocheck;
+ $self->bz_check_regexp($real_pattern) if !$nocheck;
return "NOT REGEXP_LIKE($expr, $pattern)"
}
}
sub sql_regexp {
- my ($self, $expr, $pattern, $nocheck) = @_;
+ my ($self, $expr, $pattern, $nocheck, $real_pattern) = @_;
+ $real_pattern ||= $pattern;
- $self->bz_check_regexp($pattern) if !$nocheck;
+ $self->bz_check_regexp($real_pattern) if !$nocheck;
return "$expr ~* $pattern";
}
sub sql_not_regexp {
- my ($self, $expr, $pattern, $nocheck) = @_;
+ my ($self, $expr, $pattern, $nocheck, $real_pattern) = @_;
+ $real_pattern ||= $pattern;
- $self->bz_check_regexp($pattern) if !$nocheck;
+ $self->bz_check_regexp($real_pattern) if !$nocheck;
return "$expr !~* $pattern"
}
} else {
$expr = "profiles.login_name";
}
+
+ if ($matchstr =~ /^(regexp|notregexp|exact)$/) {
+ $matchstr ||= '.';
+ }
+ else {
+ $matchstr = '' unless defined $matchstr;
+ }
+ # We can trick_taint because we use the value in a SELECT only,
+ # using a placeholder.
+ trick_taint($matchstr);
+
if ($matchtype eq 'regexp') {
- $query .= $dbh->sql_regexp($expr, '?');
- $matchstr = '.' unless $matchstr;
+ $query .= $dbh->sql_regexp($expr, '?', 0, $dbh->quote($matchstr));
} elsif ($matchtype eq 'notregexp') {
- $query .= $dbh->sql_not_regexp($expr, '?');
- $matchstr = '.' unless $matchstr;
+ $query .= $dbh->sql_not_regexp($expr, '?', 0, $dbh->quote($matchstr));
} elsif ($matchtype eq 'exact') {
$query .= $expr . ' = ?';
- $matchstr = '.' unless $matchstr;
} else { # substr or unknown
$query .= $dbh->sql_istrcmp($expr, '?', 'LIKE');
$matchstr = "%$matchstr%";
}
$nextCondition = 'AND';
- # We can trick_taint because we use the value in a SELECT only,
- # using a placeholder.
- trick_taint($matchstr);
push(@bindValues, $matchstr);
}