Revision 8545bbce
Von Sven Schöling vor mehr als 12 Jahren hinzugefügt
SL/DBUtils.pm | ||
---|---|---|
19 | 19 |
return (defined($value) && "$value" ne "") ? $value * 1 : $default; |
20 | 20 |
} |
21 | 21 |
|
22 |
# boolean escape |
|
23 |
sub conv_b { |
|
24 |
my ($value, $default) = @_; |
|
25 |
return !defined $value && defined $default ? $default |
|
26 |
: $value ? 't' |
|
27 |
: 'f'; |
|
28 |
} |
|
29 |
|
|
22 | 30 |
sub conv_date { |
23 | 31 |
my ($value) = @_; |
24 | 32 |
return (defined($value) && "$value" ne "") ? $value : undef; |
... | ... | |
307 | 315 |
my %params = @_; |
308 | 316 |
my $col = $params{col}; |
309 | 317 |
my $val = $params{val}; |
310 |
my $method = $params{method} || '='; |
|
311 | 318 |
my $escape = $params{esc} || sub { $_ }; |
319 |
my $method = $params{esc} =~ /^start|end|substr$/ ? 'ILIKE' : $params{method} || '='; |
|
312 | 320 |
|
313 | 321 |
$val = [ $val ] unless ref $val eq 'ARRAY'; |
314 | 322 |
|
315 | 323 |
my %escapes = ( |
316 | 324 |
id => \&conv_i, |
325 |
bool => \&conv_b, |
|
317 | 326 |
date => \&conv_date, |
327 |
start => sub { $_[0] . '%' }, |
|
328 |
end => sub { '%' . $_[0] }, |
|
329 |
substr => sub { '%' . $_[0] . '%' }, |
|
318 | 330 |
); |
319 | 331 |
|
332 |
my $_long_token = sub { |
|
333 |
my $op = shift; |
|
334 |
sub { |
|
335 |
my $col = shift; |
|
336 |
return scalar @_ ? join ' OR ', ("$col $op ?") x scalar @_, |
|
337 |
: undef; |
|
338 |
} |
|
339 |
}; |
|
340 |
|
|
320 | 341 |
my %methods = ( |
321 | 342 |
'=' => sub { |
322 | 343 |
my $col = shift; |
... | ... | |
324 | 345 |
: scalar @_ == 1 ? sprintf '%s = ?', $col |
325 | 346 |
: undef; |
326 | 347 |
}, |
348 |
map({ $_ => $_long_token->($_) } qw(LIKE ILIKE >= <= > <)), |
|
327 | 349 |
); |
328 | 350 |
|
329 | 351 |
$method = $methods{$method} || $method; |
Auch abrufbar als: Unified diff
DBUtils auf LIKE version von add_token gebracht.