[Bast-commits] r6969 - DBIx-Class/0.08/branches/mssql_top_fixes/t
frew at dev.catalyst.perl.org
frew at dev.catalyst.perl.org
Fri Jul 3 17:59:48 GMT 2009
Author: frew
Date: 2009-07-03 17:59:48 +0000 (Fri, 03 Jul 2009)
New Revision: 6969
Modified:
DBIx-Class/0.08/branches/mssql_top_fixes/t/42toplimit.t
Log:
fix tests for new codez
Modified: DBIx-Class/0.08/branches/mssql_top_fixes/t/42toplimit.t
===================================================================
--- DBIx-Class/0.08/branches/mssql_top_fixes/t/42toplimit.t 2009-07-03 17:54:04 UTC (rev 6968)
+++ DBIx-Class/0.08/branches/mssql_top_fixes/t/42toplimit.t 2009-07-03 17:59:48 UTC (rev 6969)
@@ -5,7 +5,7 @@
use lib qw(t/lib);
use DBICTest;
use DBIC::SqlMakerTest;
-
+$|++;
my $schema = DBICTest->init_schema;
# Trick the sqlite DB to use Top limit emulation
@@ -16,6 +16,25 @@
my $rs = $schema->resultset ('BooksInLibrary')->search ({}, { prefetch => 'owner', rows => 1, offset => 3 });
+sub default_test_order {
+ my $order_by = shift;
+ is_same_sql_bind(
+ $rs->search ({}, {order_by => $order_by})->as_query,
+ "(SELECT
+ TOP 1 me__id, source, owner, title, price, owner__id, name FROM
+ (SELECT
+ TOP 4 me.id AS me__id, me.source, me.owner, me.title, me.price, owner.id AS owner__id, owner.name
+ FROM books me
+ JOIN owners owner ON
+ owner.id = me.owner
+ WHERE ( source = ? )
+ ORDER BY me__id ASC
+ ) me ORDER BY me__id DESC
+ )",
+ [ [ source => 'Library' ] ],
+ );
+}
+
sub test_order {
my $args = shift;
@@ -26,13 +45,18 @@
is_same_sql_bind(
$rs->search ({}, {order_by => $args->{order_by}})->as_query,
- "(
- SELECT * FROM (
- SELECT TOP 1 * FROM (
- SELECT TOP 4 me.foo, me.bar, me.hello, me.goodbye, me.sensors, me.read_count FROM fourkeys me ORDER BY $args->{order_inner}
- ) foo ORDER BY $args->{order_outer}
- ) bar
- $req_order
+ "(SELECT
+ me__id, source, owner, title, price, owner__id, name FROM
+ (SELECT
+ TOP 1 me__id, source, owner, title, price, owner__id, name FROM
+ (SELECT
+ TOP 4 me.id AS me__id, me.source, me.owner, me.title, me.price, owner.id AS owner__id, owner.name FROM
+ books me
+ JOIN owners owner ON owner.id = me.owner
+ WHERE ( source = ? )
+ ORDER BY $args->{order_inner}
+ ) me ORDER BY $args->{order_outer}
+ ) me $req_order
)",
[ [ source => 'Library' ] ],
);
@@ -40,10 +64,10 @@
my @tests = (
{
- order_by => \ 'foo DESC',
+ order_by => \'foo DESC',
order_req => 'foo DESC',
order_inner => 'foo DESC',
- order_outer => 'foo ASC'
+ order_outer => 'foo ASC'
},
{
order_by => { -asc => 'foo' },
@@ -91,53 +115,38 @@
order_inner => 'foo ASC, bar DESC, hello ASC, sensors ASC',
order_outer => 'foo DESC, bar ASC, hello DESC, sensors DESC',
},
- {
- order_by => undef,
- order_req => undef,
- order_inner => 'foo ASC, bar ASC, hello ASC, goodbye ASC',
- order_outer => 'foo DESC, bar DESC, hello DESC, goodbye DESC',
- },
- {
- order_by => '',
- order_req => undef,
- order_inner => 'foo ASC, bar ASC, hello ASC, goodbye ASC',
- order_outer => 'foo DESC, bar DESC, hello DESC, goodbye DESC',
- },
- {
- order_by => {},
- order_req => undef,
- order_inner => 'foo ASC, bar ASC, hello ASC, goodbye ASC',
- order_outer => 'foo DESC, bar DESC, hello DESC, goodbye DESC',
- },
- {
- order_by => [],
- order_req => undef,
- order_inner => 'foo ASC, bar ASC, hello ASC, goodbye ASC',
- order_outer => 'foo DESC, bar DESC, hello DESC, goodbye DESC',
- },
);
-plan (tests => scalar @tests + 1);
+my @default_tests = ( undef, '', {}, [] );
+plan (tests => scalar @tests + scalar @default_tests + 1);
+
test_order ($_) for @tests;
+default_test_order ($_) for @default_tests;
+
is_same_sql_bind (
$rs->search ({}, { group_by => 'title', order_by => 'title' })->as_query,
- '(
- SELECT me__id, source, owner, title, price, owner__id, name
- FROM (
- SELECT TOP 1 me__id, source, owner, title, price, owner__id, name
- FROM (
- SELECT TOP 4 me.id AS me__id, me.source, me.owner, me.title, me.price, owner.id AS owner__id, owner.name
- FROM books me
- JOIN owners owner ON owner.id = me.owner
- WHERE ( source = ? )
- GROUP BY title
- ORDER BY title ASC
- ) AS me
- ORDER BY title DESC
- ) AS me
- ORDER BY title;
- )',
- [ [ source => 'Library' ] ],
+'(SELECT
+me.id, me.source, me.owner, me.title, me.price, owner.id, owner.name FROM
+ ( SELECT
+ id, source, owner, title, price FROM
+ ( SELECT
+ TOP 1 id, source, owner, title, price FROM
+ ( SELECT
+ TOP 4 me.id, me.source, me.owner, me.title, me.price FROM
+ books me JOIN
+ owners owner ON owner.id = me.owner
+ WHERE ( source = ? )
+ GROUP BY title
+ ORDER BY title ASC
+ ) me
+ ORDER BY title DESC
+ ) me
+ ORDER BY title
+ ) me JOIN
+ owners owner ON owner.id = me.owner WHERE
+ ( source = ? )
+ ORDER BY title)' ,
+ [ [ source => 'Library' ], [ source => 'Library' ] ],
);
More information about the Bast-commits
mailing list