use strict;
use warnings;
-use base qw/DBIx::Class::Cursor/;
+use base 'DBIx::Class::Cursor';
use Try::Tiny;
-use Scalar::Util qw/refaddr weaken/;
+use Scalar::Util qw(refaddr weaken);
+use List::Util 'shuffle';
use namespace::clean;
__PACKAGE__->mk_group_accessors('simple' =>
(undef, $sth) = $self->storage->_select( @{$self->{args}} );
- return @{$sth->fetchall_arrayref};
+ return (
+ DBIx::Class::_ENV_::SHUFFLE_UNORDERED_RESULTSETS
+ and
+ ! $self->{attrs}{order_by}
+ )
+ ? shuffle @{$sth->fetchall_arrayref}
+ : @{$sth->fetchall_arrayref}
+ ;
}
sub sth {
# add an escape for these perls ON SMOKERS - a user will still get death
PEEPEENESS => ( eval { DBICTest::RunMode->is_smoker } && ($] >= 5.013005 and $] <= 5.013006) ),
+ SHUFFLE_UNORDERED_RESULTSETS => $ENV{DBIC_SHUFFLE_UNORDERED_RESULTSETS} ? 1 : 0,
+
ASSERT_NO_INTERNAL_WANTARRAY => $ENV{DBIC_ASSERT_NO_INTERNAL_WANTARRAY} ? 1 : 0,
IV_SIZE => $Config{ivsize},
{
result_class => 'DBIx::Class::ResultClass::HashRefInflator',
prefetch => ['artist', { tracks => [qw/cd year1999cd year2000cd/] } ],
+ order_by => 'tracks.trackid',
},
)->all
],
result_class => 'DBIx::Class::ResultClass::HashRefInflator',
prefetch => ['artist', { tracks => [qw/cd year1999cd year2000cd/] } ],
columns => [qw/cdid single_track title/], # to match the columns retrieved by the virtview
+ order_by => 'tracks.trackid',
},
)->all
],
]});
warnings_exist { is_deeply (
- [ $restrict_rs->get_column('y')->all ],
- [ $y_rs->all ],
+ [ sort $restrict_rs->get_column('y')->all ],
+ [ sort $y_rs->all ],
'Zero year was correctly excluded from resultset',
) } qr/
\QUse of distinct => 1 while selecting anything other than a column \E
use Test::Exception;
use Test::More;
+
+# I *strongly* suspect Oracle has an implicit stable output order when
+# dealing with HQs. So just punt on the entire shuffle thing.
+BEGIN { $ENV{DBIC_SHUFFLE_UNORDERED_RESULTSETS} = 0 }
+
+
use DBIx::Class::Optional::Dependencies ();
use lib qw(t/lib);
my $sealed_owners = $owners->as_subselect_rs;
is_deeply (
- [ map { $_->name } ($sealed_owners->all) ],
- [ map { $_->name } ($owners->all) ],
+ [ sort map { $_->name } ($sealed_owners->all) ],
+ [ sort map { $_->name } ($owners->all) ],
"$test_type: Sort preserved from within a subquery",
);
}
use Test::More;
use Test::Warn;
use Test::Exception;
+
+# MASSIVE FIXME - there is a hole in ::RSC / as_subselect_rs
+# losing the order. Needs a rework/extract of the realiaser,
+# and that's a whole another bag of dicks
+BEGIN { $ENV{DBIC_SHUFFLE_UNORDERED_RESULTSETS} = 0 }
+
use lib qw(t/lib);
use DBICTest ':DiffSQL';
use Test::More;
+# adding implicit search criteria to the iterator will alter the test
+# mechanics - leave everything as-is instead, and hope SQLite won't
+# change too much
+BEGIN { $ENV{DBIC_SHUFFLE_UNORDERED_RESULTSETS} = 0 }
+
use lib 't/lib';
use DBICTest;
my $cd_data = { map {
$_->cdid => {
siblings => $cdrs->search ({ artist => $_->get_column('artist') })->count - 1,
- track_titles => [ map { $_->title } ($_->tracks->all) ],
+ track_titles => [ sort $_->tracks->get_column('title')->all ],
},
} ( $cdrs->all ) };
cmp_deeply (
{ map
{ $_->cdid => {
- track_titles => [ map { $_->title } ($_->tracks->all) ],
+ track_titles => [ sort map { $_->title } ($_->tracks->all) ],
siblings => $_->get_column ('sibling_count'),
} }
$c_rs->all
is ($_->tracks->count, 3, '3 tracks for CD' . $_->id );
}
+my @cdids = sort $cd_rs->get_column ('cdid')->all;
+
# Test a belongs_to prefetch of a has_many
{
my $track_rs = $schema->resultset ('Track')->search (
- { 'me.cd' => { -in => [ $cd_rs->get_column ('cdid')->all ] } },
+ { 'me.cd' => { -in => \@cdids } },
{
select => [
'me.cd',
me
)',
[ map { [ { sqlt_datatype => 'integer', dbic_colname => 'me.cd' }
- => $_ ] } ($cd_rs->get_column ('cdid')->all) ],
+ => $_ ] } @cdids ],
'count() query generated expected SQL',
);
WHERE ( me.cd IN ( ?, ?, ?, ?, ? ) )
)',
[ map { [ { sqlt_datatype => 'integer', dbic_colname => 'me.cd' }
- => $_ ] } ( ($cd_rs->get_column ('cdid')->all) x 2 ) ],
+ => $_ ] } (@cdids) x 2 ],
'next() query generated expected SQL',
);
# RT 47779, test group_by as a scalar ref
{
my $track_rs = $schema->resultset ('Track')->search (
- { 'me.cd' => { -in => [ $cd_rs->get_column ('cdid')->all ] } },
+ { 'me.cd' => { -in => \@cdids } },
{
select => [
'me.cd',
me
)',
[ map { [ { sqlt_datatype => 'integer', dbic_colname => 'me.cd' }
- => $_ ] } ($cd_rs->get_column ('cdid')->all) ],
+ => $_ ] } (@cdids) ],
'count() query generated expected SQL',
);
}
});
is_deeply(
- $rs->all_hri,
+ $rs->search({}, { order_by => 'me.title' })->all_hri,
[
{ title => "Caterwaulin' Blues", max_trk => 3 },
{ title => "Come Be Depressed With Us", max_trk => 3 },
use Test::More;
use Test::Exception;
+# MASSIVE FIXME - there is a hole in ::RSC / as_subselect_rs
+# losing the order. Needs a rework/extract of the realiaser,
+# and that's a whole another bag of dicks
+BEGIN { $ENV{DBIC_SHUFFLE_UNORDERED_RESULTSETS} = 0 }
+
use DBICTest::Schema::CD;
BEGIN {
# the default scalarref table name will not work well for this test
# [qw/2 2 /],
#]);
my ($ta, $tb) = $schema->resultset ('TwoKeys')
- ->search ( [ { artist => 1, cd => 1 }, { artist => 2, cd => 2 } ])
+ ->search ( [ { artist => 1, cd => 1 }, { artist => 2, cd => 2 } ], { order_by => 'artist' })
->all;
my $tkfk_cnt = $tkfks->count;
is ($fc->discard_changes->read_count, 30, 'Update did not touch outlier');
# make the multi-join stick
-my $fks_multi = $fks->search({ 'fourkeys_to_twokeys.pilot_sequence' => { '!=' => 666 } });
+my $fks_multi = $fks->search(
+ { 'fourkeys_to_twokeys.pilot_sequence' => { '!=' => 666 } },
+ { order_by => [ $fks->result_source->primary_columns ] },
+);
$schema->is_executed_sql_bind( sub {
$fks_multi->update ({ read_count => \ 'read_count + 1' })
}, [
ON fourkeys_to_twokeys.f_bar = me.bar AND fourkeys_to_twokeys.f_foo = me.foo AND fourkeys_to_twokeys.f_goodbye = me.goodbye AND fourkeys_to_twokeys.f_hello = me.hello
WHERE ( bar = ? OR bar = ? ) AND ( foo = ? OR foo = ? ) AND fourkeys_to_twokeys.pilot_sequence != ? AND ( goodbye = ? OR goodbye = ? ) AND ( hello = ? OR hello = ? ) AND sensors != ?
GROUP BY me.foo, me.bar, me.hello, me.goodbye
+ ORDER BY foo, bar, hello, goodbye
',
(1, 2) x 2,
666,
ON fourkeys_to_twokeys.f_bar = me.bar AND fourkeys_to_twokeys.f_foo = me.foo AND fourkeys_to_twokeys.f_goodbye = me.goodbye AND fourkeys_to_twokeys.f_hello = me.hello
WHERE "blah" = "bleh" AND ( bar = ? OR bar = ? ) AND ( foo = ? OR foo = ? ) AND fourkeys_to_twokeys.pilot_sequence != ? AND ( goodbye = ? OR goodbye = ? ) AND ( hello = ? OR hello = ? ) AND sensors != ?
GROUP BY me.foo, me.bar, me.hello, me.goodbye
+ ORDER BY foo, bar, hello, goodbye
',
(1, 2) x 2,
666,
AND fourkeys_to_twokeys.f_goodbye = me.goodbye
AND fourkeys_to_twokeys.f_hello = me.hello
WHERE ( bar = ? OR bar = ? ) AND ( foo = ? OR foo = ? ) AND fourkeys_to_twokeys.pilot_sequence != ? AND ( goodbye = ? OR goodbye = ? ) AND ( hello = ? OR hello = ? ) AND sensors != ?
+ ORDER BY foo, bar, hello, goodbye
)
)
',