required => 1
);
- has name_separator => (
+ has ident_separator => (
is => 'rw',
isa => NameSeparator,
default => '.',
or => $self->can('_recurse_where'),
map { +"$_" => $self->can("_$_") } qw/
value
- name
+ identifier
true
false
expr
return $output;
}
- method _name(AST $ast) {
- my @names = @{$ast->{args}};
+ method _identifier(AST $ast) {
+ my @names = @{$ast->{elements}};
- my $sep = $self->name_separator;
+ my $sep = $self->ident_separator;
my $quote = $self->is_quoting
? $self->quote_chars
: [ '' ];
);
$args{quote_chars} = $self->quote_char
if $self->has_quote_chars;
- $args{name_sep} = $self->name_sep
+ $args{ident_separator} = $self->name_sep
if $self->has_name_sep;
# TODO: this needs improving along with SQL::A::create
@names = split /\Q@{[$self->name_sep]}\E/, $names[0]
if (@names == 1 && $self->has_name_sep);
- my $ast = { -type => 'name', args => [ @names ] };
+ my $ast = { -type => 'identifier', elements => [ @names ] };
return $ast
unless $use_convert && $self->has_field_convertor;
my $sqla = SQL::Abstract->create(1);
# TODO: once MXMS supports %args, use that here
-is $sqla->dispatch( { -type => 'name', args => [qw/me id/] }), "me.id",
- "Simple name generator";
+is $sqla->dispatch( { -type => 'identifier', elements => [qw/me id/] }), "me.id",
+ "Simple identifier generator";
-is $sqla->dispatch( { -type => 'name', args => ['*'] } ),
+is $sqla->dispatch( { -type => 'identifier', elements => ['*'] } ),
"*",
- "* name generator";
+ "* identifier generator";
-is $sqla->dispatch( { -type => 'name', args => [qw/me */]}),
+is $sqla->dispatch( { -type => 'identifier', elements => [qw/me */]}),
"me.*",
- "Simple name generator";
+ "Simple identifier generator";
$sqla->quote_chars(['`']);
-is $sqla->dispatch( { -type => 'name', args => [qw/me */]}),
+is $sqla->dispatch( { -type => 'identifier', elements => [qw/me */]}),
"`me`.*",
- "Simple name generator";
+ "Simple identifier generator";
$sqla->disable_quoting;
is $sqla->dispatch(
{ -type => 'list',
args => [
- { -type => name => args => [qw/me id/] },
- { -type => name => args => [qw/me foo bar/] },
- { -type => name => args => [qw/bar/] }
+ { -type => identifier => elements => [qw/me id/] },
+ { -type => identifier => elements => [qw/me foo bar/] },
+ { -type => identifier => elements => [qw/bar/] }
]
}
), "me.id, me.foo.bar, bar",
"List generator";
is $sqla->dispatch(
- { -type => 'alias', ident => { -type => name => args => [qw/me id/]}, as => "foobar" }
+ { -type => 'alias', ident => { -type => identifier => elements => [qw/me id/]}, as => "foobar" }
), "me.id AS foobar",
"Alias generator";
} "coercion of quote_chars from Str works";
-is $sqla->dispatch( { -type => 'name', args => [qw/me id/] }),
+is $sqla->dispatch( { -type => 'identifier', elements => [qw/me id/] }),
"[me].[id]",
"me.id";
-is $sqla->dispatch( { -type => 'name', args => [qw/me */] }),
+is $sqla->dispatch( { -type => 'identifier', elements => [qw/me */] }),
"[me].*",
"me.*";
-is $sqla->dispatch( { -type => 'name', args => [qw/*/] }),
+is $sqla->dispatch( { -type => 'identifier', elements => [qw/*/] }),
"*",
"*";
{ -type => 'expr',
op => '>',
args => [
- {-type => name => args => [qw/me id/] },
+ {-type => identifier => elements => [qw/me id/] },
{ -type => 'value', value => 500 }
]
}
{ -type => 'expr',
op => '>',
args => [
- {-type => 'name', args => [qw/me id/]},
+ {-type => 'identifier', elements => [qw/me id/]},
{-type => 'value', value => 500 }
]
}
{ -type => 'expr',
op => '>',
args => [
- {-type => 'name', args => [qw/me id/]},
+ {-type => 'identifier', elements => [qw/me id/]},
{-type => 'value', value => 500 }
]
},
{ -type => 'expr',
op => '==',
args => [
- {-type => 'name', args => [qw/me name/]},
+ {-type => 'identifier', elements => [qw/me name/]},
{-type => 'value', value => '200' }
]
},
{ -type => 'expr', op => 'or',
args => [
{ -type => 'expr', op => '==',
- args => [ {-type => 'name', args => [qw/me name/] }, {-type => 'value', value => 500 } ]
+ args => [ {-type => 'identifier', elements => [qw/me name/] }, {-type => 'value', value => 500 } ]
},
{ -type => 'expr', op => 'or', args => $cols }
]
{ -type => 'expr', op => 'or',
args => [
{ -type => 'expr', op => '==',
- args => [ {-type => 'name', args => [qw/me name/] }, {-type => 'value', value => 500 } ]
+ args => [ {-type => 'identifier', elements => [qw/me name/] }, {-type => 'value', value => 500 } ]
},
{ -type => 'expr', op => 'and', args => $cols }
]
is $sqla->dispatch(
{ -type => 'expr', op => 'and', args => [
{ -type => 'expr', op => '==', args => [
- {-type => 'name', args => [qw/me id/] }, {-type => 'value', value => 200 }
+ {-type => 'identifier', elements => [qw/me id/] }, {-type => 'value', value => 200 }
],
},
{ -type => 'expr', op => 'and', args => $cols }
is $sqla->dispatch(
{ -type => 'expr', op => 'and', args => [
{ -type => 'expr', op => '==', args => [
- {-type => 'name', args => [qw/me id/] }, {-type => 'value', value => 200 }
+ {-type => 'identifier', elements => [qw/me id/] }, {-type => 'value', value => 200 }
],
},
{ -type => 'expr', op => 'or', args => $cols }
is $sqla->dispatch(
{ -type => 'expr',
op => 'in',
- args => [ { -type => 'name', args => ['foo'] } ],
+ args => [ { -type => 'identifier', elements => ['foo'] } ],
}
), "0 = 1", "emtpy -in";
{ -type => 'expr',
op => 'in',
args => [
- {-type => 'name', args => [qw/me id/] },
+ {-type => 'identifier', elements => [qw/me id/] },
{-type => 'value', value => 100 },
{-type => 'value', value => 200 },
{-type => 'value', value => 300 },
{ -type => 'expr',
op => 'not_in',
args => [
- {-type => 'name', args => [qw/me id/] },
+ {-type => 'identifier', elements => [qw/me id/] },
{-type => 'value', value => 100 },
{-type => 'value', value => 200 },
{-type => 'value', value => 300 },
{ -type => 'expr',
op => 'like',
args => [
- {-type => name => args => [qw/me id/] },
+ {-type => identifier => elements => [qw/me id/] },
{ -type => 'value', value => 500 }
]
}
{ -type => 'expr',
op => '==',
args => [
- {-type => name => args => [qw/me id/] },
+ {-type => identifier => elements => [qw/me id/] },
{ -type => 'value', value => undef }
]
}
{ -type => 'expr',
op => '!=',
args => [
- {-type => name => args => [qw/me id/] },
+ {-type => identifier => elements => [qw/me id/] },
{ -type => 'value', value => undef }
]
}
{ -type => 'expr',
op => 'ROUND',
args => [
- {-type => name => args => [qw/me id/] },
+ {-type => identifier => elements => [qw/me id/] },
]
},
{ -type => 'expr',
{ -type => 'expr',
op => 'between',
args => [
- {-type => name => args => [qw/me id/] },
+ {-type => identifier => elements => [qw/me id/] },
{ -type => 'value', value => 500 },
{ -type => 'value', value => 599 },
],
my $sqla = SQL::Abstract->create(1);
-my $foo = {-type => name => args => [qw/foo/]};
-my $bar = {-type => name => args => [qw/bar/]},
-my $fnord = {-type => name => args => [qw/fnord/]};
+my $foo = {-type => identifier => elements => [qw/foo/]};
+my $bar = {-type => identifier => elements => [qw/bar/]},
+my $fnord = {-type => identifier => elements => [qw/fnord/]};
-my $foo_id = { -type => 'name', args => [qw/foo id/] };
-my $me_foo_id = { -type => 'name', args => [qw/me foo_id/] };
+my $foo_id = { -type => 'identifier', elements => [qw/foo id/] };
+my $me_foo_id = { -type => 'identifier', elements => [qw/me foo_id/] };
is $sqla->dispatch(
{ -type => 'join',
"simple join clause";
-$foo_id = { -type => 'name', args => [qw/foo_id/] };
+$foo_id = { -type => 'identifier', elements => [qw/foo_id/] };
is $sqla->dispatch(
{ -type => 'join',
my $foo_as_me = {
-type => 'alias',
- ident => {-type => 'name', args => [qw/foo/]},
+ ident => {-type => 'identifier', elements => [qw/foo/]},
as => 'me'
};
-my $me_foo_id = { -type => 'name', args => [qw/me foo_id/] };
+my $me_foo_id = { -type => 'identifier', elements => [qw/me foo_id/] };
is $sqla->dispatch(
{ -type => 'select',
tablespec => $foo_as_me,
columns => [
- { -type => 'name', args => [qw/me id/] },
+ { -type => 'identifier', elements => [qw/me id/] },
{ -type => 'alias', ident => $me_foo_id, as => 'foo' },
]
}
is $sqla->dispatch(
{ -type => 'select',
columns => [
- { -type => 'name', args => [qw/me id/] },
+ { -type => 'identifier', elements => [qw/me id/] },
{ -type => 'alias', ident => $me_foo_id, as => 'foo' },
- { -type => 'name', args => [qw/bar name/] },
+ { -type => 'identifier', elements => [qw/bar name/] },
],
tablespec => {
-type => 'join',
lhs => $foo_as_me,
- rhs => {-type => 'name', args => [qw/bar/] },
+ rhs => {-type => 'identifier', elements => [qw/bar/] },
on => {
-type => 'expr',
op => '==',
args => [
- {-type => 'name', args => [qw/bar id/]},
- {-type => 'name', args => [qw/me bar_id/]}
+ {-type => 'identifier', elements => [qw/bar id/]},
+ {-type => 'identifier', elements => [qw/me bar_id/]}
],
}
},
is $sqla->dispatch(
{ -type => 'select',
columns => [
- { -type => 'name', args => [qw/me */] },
+ { -type => 'identifier', elements => [qw/me */] },
],
tablespec => $foo_as_me,
where => {
-type => 'expr',
op => '==',
args => [
- {-type => 'name', args => [qw/me id/]},
+ {-type => 'identifier', elements => [qw/me id/]},
{-type => 'value', value => 1 },
]
}
{ -type => 'select',
tablespec => $foo_as_me,
columns => [
- { -type => 'name', args => [qw/me id/] },
+ { -type => 'identifier', elements => [qw/me id/] },
{ -type => 'alias', ident => $me_foo_id, as => 'foo' },
],
order_by => [
- { -type => 'ordering', expr => { -type => 'name', args => [qw/me name/] }, direction => 'desc' },
+ { -type => 'ordering', expr => { -type => 'identifier', elements => [qw/me name/] }, direction => 'desc' },
$me_foo_id,
]
}
is $sqla->dispatch(
- { -type => 'ordering', expr => { -type => name => args => [qw/me date/ ] } }
+ { -type => 'ordering', expr => { -type => identifier => elements => [qw/me date/ ] } }
), "me.date",
"basic ordering";
is $sqla->dispatch(
{ -type => 'ordering',
- expr => { -type => name => args => [qw/me date/] },
+ expr => { -type => identifier => elements => [qw/me date/] },
direction => 'DESC'
}
), "me.date DESC",
is $sqla->dispatch(
{ -type => 'ordering',
- expr => { -type => name => args => [qw/me date/] },
+ expr => { -type => identifier => elements => [qw/me date/] },
direction => 'asc'
}
), "me.date ASC",
$sqla->dispatch(
{ -type => 'expr', op => '==',
args => [
- { -type => 'name', args => [qw/me id/] },
- { -type => 'alias', ident => { -type => 'name', args => [qw/me id/] }, as => 'bar' }
+ { -type => 'identifier', elements => [qw/me id/] },
+ { -type => 'alias', ident => { -type => 'identifier', elements => [qw/me id/] }, as => 'bar' }
]
}
)
throws_ok {
$sqla->dispatch(
- { -type => 'alias', iden => { -type => 'name', args => ['id'] }, as => 'foo' } # iden not ident
+ { -type => 'alias', iden => { -type => 'identifier', elements => ['id'] }, as => 'foo' } # iden not ident
)
} qr/foobar/, "alias: iden instead of ident";
ok(my $visitor = SQL::Abstract::Compat->new);
-my $foo_id = { -type => 'name', args => [qw/foo/] };
-my $bar_id = { -type => 'name', args => [qw/bar/] };
+my $foo_id = { -type => 'identifier', elements => [qw/foo/] };
+my $bar_id = { -type => 'identifier', elements => [qw/bar/] };
my $foo_eq_1 = field_op_value($foo_id, '==', 1);
my $bar_eq_str = field_op_value($bar_id, '==', 'some str');
-type => 'expr',
op => '==',
args => [
- { -type => 'name', args => ['worker'] },
+ { -type => 'identifier', elements => ['worker'] },
{ -type => 'value', value => $_[0] },
],
}
'test', '*', [ { ticket => [11, 12, 13] } ]
),
{ -type => 'select',
- columns => [ { -type => 'name', args => ['*'] } ],
- tablespec => { -type => 'name', args => ['test'] },
+ columns => [ { -type => 'identifier', elements => ['*'] } ],
+ tablespec => { -type => 'identifier', elements => ['test'] },
where => $ticket_or_eq
},
"Complex AST with convert('UPPER')";
]
),
{ -type => 'select',
- columns => [ { -type => 'name', args => ['*'] } ],
- tablespec => { -type => 'name', args => ['test'] },
+ columns => [ { -type => 'identifier', elements => ['*'] } ],
+ tablespec => { -type => 'identifier', elements => ['test'] },
where => $hostname_and_ticket
},
"Complex AST mixing arrays+hashes with convert('UPPER')";
]
),
{ -type => 'select',
- columns => [ { -type => 'name', args => ['*'] } ],
- tablespec => { -type => 'name', args => ['test'] },
+ columns => [ { -type => 'identifier', elements => ['*'] } ],
+ tablespec => { -type => 'identifier', elements => ['test'] },
where => {
-type => 'expr',
op => 'or',
]
),
{ -type => 'select',
- columns => [ { -type => 'name', args => ['*'] } ],
- tablespec => { -type => 'name', args => ['test'] },
+ columns => [ { -type => 'identifier', elements => ['*'] } ],
+ tablespec => { -type => 'identifier', elements => ['test'] },
where => {
-type => 'expr',
op => 'or',
]
),
{ -type => 'select',
- columns => [ { -type => 'name', args => ['*'] } ],
- tablespec => { -type => 'name', args => ['test'] },
+ columns => [ { -type => 'identifier', elements => ['*'] } ],
+ tablespec => { -type => 'identifier', elements => ['test'] },
where => {
-type => 'expr',
op => 'or',
$field = ref $field eq 'HASH'
? $field
: ref $field eq 'ARRAY'
- ? { -type => 'name', args => $field }
- : { -type => 'name', args => [$field] };
+ ? { -type => 'identifier', elements => $field }
+ : { -type => 'identifier', elements => [$field] };
my @value = ref $value eq 'HASH'
? $value
$field = ref $field eq 'HASH'
? $field
: ref $field eq 'ARRAY'
- ? { -type => 'name', args => $field }
- : { -type => 'name', args => [$field] };
+ ? { -type => 'identifier', elements => $field }
+ : { -type => 'identifier', elements => [$field] };
return $field;
}