);
my $tests = {
+
LimitOffset => {
ordered_limit_offset => [
'(
- SELECT me.id, ? * ?, ?
+ SELECT me.id, owner.id, owner.name, ? * ?, ?
FROM books me
+ JOIN owners owner
+ ON owner.id = me.owner
WHERE source != ? AND me.title = ? AND source = ?
GROUP BY avg(me.id / ?)
HAVING ?
LimitXY => {
ordered_limit_offset => [
'(
- SELECT me.id, ? * ?, ?
+ SELECT me.id, owner.id, owner.name, ? * ?, ?
FROM books me
+ JOIN owners owner
+ ON owner.id = me.owner
WHERE source != ? AND me.title = ? AND source = ?
GROUP BY avg(me.id / ?)
HAVING ?
SkipFirst => {
ordered_limit_offset => [
'(
- SELECT SKIP ? FIRST ? me.id, ? * ?, ?
+ SELECT SKIP ? FIRST ? me.id, owner.id, owner.name, ? * ?, ?
FROM books me
+ JOIN owners owner
+ ON owner.id = me.owner
WHERE source != ? AND me.title = ? AND source = ?
GROUP BY avg(me.id / ?)
HAVING ?
FirstSkip => {
ordered_limit_offset => [
'(
- SELECT FIRST ? SKIP ? me.id, ? * ?, ?
+ SELECT FIRST ? SKIP ? me.id, owner.id, owner.name, ? * ?, ?
FROM books me
+ JOIN owners owner
+ ON owner.id = me.owner
WHERE source != ? AND me.title = ? AND source = ?
GROUP BY avg(me.id / ?)
HAVING ?
RowNumberOver => do {
my $unordered_sql = '(
- SELECT me.id, bar, baz
+ SELECT me.id, owner__id, owner__name, bar, baz
FROM (
- SELECT me.id, bar, baz, ROW_NUMBER() OVER() AS rno__row__index
+ SELECT me.id, owner__id, owner__name, bar, baz, ROW_NUMBER() OVER() AS rno__row__index
FROM (
- SELECT me.id, ? * ? AS bar, ? AS baz
+ SELECT me.id, owner.id AS owner__id, owner.name AS owner__name, ? * ? AS bar, ? AS baz
FROM books me
+ JOIN owners owner
+ ON owner.id = me.owner
WHERE source != ? AND me.title = ? AND source = ?
GROUP BY avg(me.id / ?)
HAVING ?
)';
my $ordered_sql = '(
- SELECT me.id, bar, baz
+ SELECT me.id, owner__id, owner__name, bar, baz
FROM (
- SELECT me.id, bar, baz, ROW_NUMBER() OVER( ORDER BY ORDER__BY__1, ORDER__BY__2 ) AS rno__row__index
+ SELECT me.id, owner__id, owner__name, bar, baz, ROW_NUMBER() OVER( ORDER BY ORDER__BY__1, ORDER__BY__2 ) AS rno__row__index
FROM (
- SELECT me.id, ? * ? AS bar, ? AS baz,
+ SELECT me.id, owner.id AS owner__id, owner.name AS owner__name, ? * ? AS bar, ? AS baz,
? / ? AS ORDER__BY__1, ? AS ORDER__BY__2
FROM books me
+ JOIN owners owner
+ ON owner.id = me.owner
WHERE source != ? AND me.title = ? AND source = ?
GROUP BY avg(me.id / ?)
HAVING ?
RowNum => do {
my $limit_sql = sub {
sprintf '(
- SELECT me.id, bar, baz
+ SELECT me.id, owner__id, owner__name, bar, baz
FROM (
- SELECT me.id, ? * ? AS bar, ? AS baz
+ SELECT me.id, owner.id AS owner__id, owner.name AS owner__name, ? * ? AS bar, ? AS baz
FROM books me
+ JOIN owners owner
+ ON owner.id = me.owner
WHERE source != ? AND me.title = ? AND source = ?
GROUP BY avg(me.id / ?)
HAVING ?
],
limit_offset => [
'(
- SELECT me.id, bar, baz
+ SELECT me.id, owner__id, owner__name, bar, baz
FROM (
- SELECT me.id, bar, baz, ROWNUM rownum__index
+ SELECT me.id, owner__id, owner__name, bar, baz, ROWNUM rownum__index
FROM (
- SELECT me.id, ? * ? AS bar, ? AS baz
+ SELECT me.id, owner.id AS owner__id, owner.name AS owner__name, ? * ? AS bar, ? AS baz
FROM books me
+ JOIN owners owner
+ ON owner.id = me.owner
WHERE source != ? AND me.title = ? AND source = ?
GROUP BY avg(me.id / ?)
HAVING ?
],
ordered_limit_offset => [
'(
- SELECT me.id, bar, baz
+ SELECT me.id, owner__id, owner__name, bar, baz
FROM (
- SELECT me.id, bar, baz, ROWNUM rownum__index
+ SELECT me.id, owner__id, owner__name, bar, baz, ROWNUM rownum__index
FROM (
- SELECT me.id, ? * ? AS bar, ? AS baz
+ SELECT me.id, owner.id AS owner__id, owner.name AS owner__name, ? * ? AS bar, ? AS baz
FROM books me
+ JOIN owners owner
+ ON owner.id = me.owner
WHERE source != ? AND me.title = ? AND source = ?
GROUP BY avg(me.id / ?)
HAVING ?
};
},
-
FetchFirst => {
limit => [
'(
- SELECT me.id, ? * ?, ?
+ SELECT me.id, owner.id, owner.name, ? * ?, ?
FROM books me
+ JOIN owners owner
+ ON owner.id = me.owner
WHERE source != ? AND me.title = ? AND source = ?
GROUP BY avg(me.id / ?)
HAVING ?
],
limit_offset => [
'(
- SELECT me.id, bar, baz
+ SELECT me.id, owner__id, owner__name, bar, baz
FROM (
- SELECT me.id, ? * ? AS bar, ? AS baz
+ SELECT me.id, owner.id AS owner__id, owner.name AS owner__name, ? * ? AS bar, ? AS baz
FROM books me
+ JOIN owners owner
+ ON owner.id = me.owner
WHERE source != ? AND me.title = ? AND source = ?
GROUP BY avg(me.id / ?)
HAVING ?
],
ordered_limit => [
'(
- SELECT me.id, ? * ?, ?
+ SELECT me.id, owner.id, owner.name, ? * ?, ?
FROM books me
+ JOIN owners owner
+ ON owner.id = me.owner
WHERE source != ? AND me.title = ? AND source = ?
GROUP BY avg(me.id / ?)
HAVING ?
],
ordered_limit_offset => [
'(
- SELECT me.id, bar, baz
+ SELECT me.id, owner__id, owner__name, bar, baz
FROM (
- SELECT me.id, bar, baz, ORDER__BY__1, ORDER__BY__2
+ SELECT me.id, owner__id, owner__name, bar, baz, ORDER__BY__1, ORDER__BY__2
FROM (
- SELECT me.id, ? * ? AS bar, ? AS baz, ? / ? AS ORDER__BY__1, ? AS ORDER__BY__2
+ SELECT me.id, owner.id AS owner__id, owner.name AS owner__name, ? * ? AS bar, ? AS baz, ? / ? AS ORDER__BY__1, ? AS ORDER__BY__2
FROM books me
+ JOIN owners owner
+ ON owner.id = me.owner
WHERE source != ? AND me.title = ? AND source = ?
GROUP BY avg(me.id / ?)
HAVING ?
Top => {
limit => [
'(
- SELECT TOP 4 me.id, ? * ?, ?
+ SELECT TOP 4 me.id, owner.id, owner.name, ? * ?, ?
FROM books me
+ JOIN owners owner
+ ON owner.id = me.owner
WHERE source != ? AND me.title = ? AND source = ?
GROUP BY avg(me.id / ?)
HAVING ?
],
limit_offset => [
'(
- SELECT TOP 4 me.id, bar, baz
+ SELECT TOP 4 me.id, owner__id, owner__name, bar, baz
FROM (
- SELECT TOP 7 me.id, ? * ? AS bar, ? AS baz
+ SELECT TOP 7 me.id, owner.id AS owner__id, owner.name AS owner__name, ? * ? AS bar, ? AS baz
FROM books me
+ JOIN owners owner
+ ON owner.id = me.owner
WHERE source != ? AND me.title = ? AND source = ?
GROUP BY avg(me.id / ?)
HAVING ?
],
ordered_limit => [
'(
- SELECT TOP 4 me.id, ? * ?, ?
+ SELECT TOP 4 me.id, owner.id, owner.name, ? * ?, ?
FROM books me
+ JOIN owners owner
+ ON owner.id = me.owner
WHERE source != ? AND me.title = ? AND source = ?
GROUP BY avg(me.id / ?)
HAVING ?
],
ordered_limit_offset => [
'(
- SELECT me.id, bar, baz
+ SELECT me.id, owner__id, owner__name, bar, baz
FROM (
- SELECT TOP 4 me.id, bar, baz, ORDER__BY__1, ORDER__BY__2
+ SELECT TOP 4 me.id, owner__id, owner__name, bar, baz, ORDER__BY__1, ORDER__BY__2
FROM (
- SELECT TOP 7 me.id, ? * ? AS bar, ? AS baz, ? / ? AS ORDER__BY__1, ? AS ORDER__BY__2
+ SELECT TOP 7 me.id, owner.id AS owner__id, owner.name AS owner__name, ? * ? AS bar, ? AS baz, ? / ? AS ORDER__BY__1, ? AS ORDER__BY__2
FROM books me
+ JOIN owners owner
+ ON owner.id = me.owner
WHERE source != ? AND me.title = ? AND source = ?
GROUP BY avg(me.id / ?)
HAVING ?
limit => [
'(
SET ROWCOUNT 4
- SELECT me.id, ? * ?, ?
+ SELECT me.id, owner.id, owner.name, ? * ?, ?
FROM books me
+ JOIN owners owner
+ ON owner.id = me.owner
WHERE source != ? AND me.title = ? AND source = ?
GROUP BY avg(me.id / ?)
HAVING ?
],
limit_offset => [
'(
- SELECT me.id, bar, baz
+ SELECT me.id, owner__id, owner__name, bar, baz
FROM (
- SELECT me.id, ? * ? AS bar, ? AS baz
+ SELECT me.id, owner.id AS owner__id, owner.name AS owner__name, ? * ? AS bar, ? AS baz
FROM books me
+ JOIN owners owner
+ ON owner.id = me.owner
WHERE source != ? AND me.title = ? AND source = ?
GROUP BY avg( me.id / ? )
HAVING ?
GenericSubQ => {
limit => [
'(
- SELECT me.id, bar, baz
+ SELECT me.id, owner__id, owner__name, bar, baz
FROM (
- SELECT me.id, ? * ? AS bar, ? AS baz
+ SELECT me.id, owner.id AS owner__id, owner.name AS owner__name, ? * ? AS bar, ? AS baz
FROM books me
+ JOIN owners owner
+ ON owner.id = me.owner
WHERE source != ? AND me.title = ? AND source = ?
GROUP BY avg( me.id / ? )
HAVING ?
],
limit_offset => [
'(
- SELECT me.id, bar, baz
+ SELECT me.id, owner__id, owner__name, bar, baz
FROM (
- SELECT me.id, ? * ? AS bar, ? AS baz
+ SELECT me.id, owner.id AS owner__id, owner.name AS owner__name, ? * ? AS bar, ? AS baz
FROM books me
+ JOIN owners owner
+ ON owner.id = me.owner
WHERE source != ? AND me.title = ? AND source = ?
GROUP BY avg( me.id / ? )
HAVING ?
for my $limtype (sort keys %$tests) {
+ Test::Builder->new->is_passing or exit;
+
delete $schema->storage->_sql_maker->{_cached_syntax};
$schema->storage->_sql_maker->limit_dialect ($limtype);
# chained search is necessary to exercise the recursive {where} parser
my $rs = $schema->resultset('BooksInLibrary')->search({ 'me.title' => { '=' => 'kama sutra' } })->search({ source => { '!=', 'Study' } }, {
- columns => { identifier => 'me.id' }, # people actually do that. BLEH!!! :)
+ columns => [ { identifier => 'me.id' }, 'owner.id', 'owner.name' ], # people actually do that. BLEH!!! :)
+ join => 'owner', # single-rel manual prefetch
rows => 4,
'+columns' => { bar => \['? * ?', [ $attr => 11 ], [ $attr => 12 ]], baz => \[ '?', [ $attr => 13 ]] },
group_by => \[ 'avg(me.id / ?)', [ $attr => 21 ] ],