'=' => '==',
);
+ has convert => (
+ is => 'rw',
+ isa => 'Str',
+ predicate => 'has_field_convertor'
+ );
+
method select(Str|ArrayRef|ScalarRef $from, ArrayRef|Str $fields,
WhereType $where?,
WhereType $order?)
-type => 'select',
columns => [
map {
- $self->mk_name($_)
+ $self->mk_name(0, $_)
} ( is_Str($fields) ? $fields : @$fields )
],
tablespec => $self->tablespec($from)
}
sub mk_name {
- shift;
- return { -type => 'name', args => [ @_ ] };
+ my ($self, $use_convert) = (shift,shift);
+ my $ast = { -type => 'name', args => [ @_ ] };
+
+ return $ast
+ unless $use_convert && $self->has_field_convertor;
+
+ return $self->apply_convert($ast);
}
method tablespec(Str|ArrayRef|ScalarRef $from) {
- return $self->mk_name($from)
+ return $self->mk_name(0, $from)
if is_Str($from);
}
-type => 'expr',
op => $op,
args => [
- { -type => 'name', args => [$key] }
+ $self->mk_name(1, $key)
],
};
}
method value($value) returns (AST) {
- return { -type => 'value', value => $value }
+ return $self->apply_convert( { -type => 'value', value => $value })
if is_Str($value);
confess "Don't know how to handle terminal value " . dump($value);
}
+ method apply_convert(AST $ast) {
+ return $ast unless $self->has_field_convertor;
+
+ return {
+ -type => 'expr',
+ op => $self->convert,
+ args => [ $ast ]
+ };
+ }
+
}
args => {cmp => "like"},
stmt => 'SELECT * FROM test WHERE ( a LIKE ? AND b LIKE ? )'
},
-);
-my @foo = (
#7
{
args => {logic => "or", cmp => "like"},
},
#8
{
+ todo => 'lower',
args => {case => "lower"},
stmt => 'select * from test where ( a = ? and b = ? )'
},
#9
{
+ todo => 'lower',
args => {case => "lower", cmp => "="},
stmt => 'select * from test where ( a = ? and b = ? )'
},
#10
{
+ todo => 'lower',
args => {case => "lower", cmp => "like"},
stmt => 'select * from test where ( a like ? and b like ? )'
},
#11
{
+ todo => 'lower',
args => {case => "lower", convert => "lower", cmp => "like"},
stmt => 'select * from test where ( lower(a) like lower(?) and lower(b) like lower(?) )'
},
},
#13
{
+ todo => 'lower',
args => {convert => "lower"},
stmt => 'SELECT * FROM test WHERE ( ( LOWER(ticket) = LOWER(?) ) OR ( LOWER(hostname) = LOWER(?) ) OR ( LOWER(taco) = LOWER(?) ) OR ( LOWER(salami) = LOWER(?) ) )',
where => [ { ticket => 11 }, { hostname => 11 }, { taco => 'salad' }, { salami => 'punch' } ],
my $where = $_->{where} || { a => 4, b => 0};
my($stmt, @bind) = $sql->select('test', '*', $where);
+ local $TODO = $_->{todo};
# LDNOTE: this original test suite from NWIGER did no comparisons
# on @bind values, just checking if @bind is nonempty.