- Make sure deployment_statements() and cursor_class() are called on
a resolved storage subclass
+ * Misc
+ - Fix tests failing due to unspecified resultset retrieval order
+ (test suite now will pass with newest SQLite libs)
+
0.08210 2013-04-04 15:30 (UTC)
* New Features / Changes
- Officially deprecate the 'cols' and 'include_columns' resultset
for var in $(grep -P '\$ENV\{' -r lib/ | grep -oP 'DBIC_\w+' | sort -u | grep -v DBIC_TRACE) ; do
export $var=1
done
+
+ export DBICTEST_SQLITE_REVERSE_DEFAULT_ORDER=1
fi
# try Schwern's latest offering on a stock perl and a threaded blead
{
require DBICTest;
my $s = DBICTest->init_schema;
- is ($s->resultset('Artist')->next->name, 'Caterwauler McCrae');
+ is ($s->resultset('Artist')->find(1)->name, 'Caterwauler McCrae');
assert_no_missing_expected_requires();
}
my $search = [ { 'tags.tag' => 'Cheesy' }, { 'tags.tag' => 'Blue' } ];
-my( $or_rs ) = $schema->resultset("CD")->search_rs($search, { join => 'tags',
+my $or_rs = $schema->resultset("CD")->search_rs($search, { join => 'tags',
order_by => 'cdid' });
is($or_rs->all, 5, 'Joined search with OR returned correct number of rows');
is($or_rs->count, 5, 'Search count with OR ok');
my $tag_rs = $schema->resultset('Tag')->search(
[ { 'me.tag' => 'Cheesy' }, { 'me.tag' => 'Blue' } ]);
-my $rel_rs = $tag_rs->search_related('cd');
+my $rel_rs = $tag_rs->search_related('cd', {}, { order_by => 'cd.cdid'} );
is($rel_rs->count, 5, 'Related search ok');
# make sure the ident condition is assembled sanely
{
- my $artist = $schema->resultset('Artist')->next;
+ my $artist = $schema->resultset('Artist')->find(1);
my ($sql, @bind);
my $old_debugobj = $schema->storage->debugobj;
prefetch => {
cds => 'tags'
},
+ order_by => { -desc => 'cds.cdid' },
}
);
{
is($queries, 1, 'only one SQL statement executed');
-$schema->storage->debug($sdebug);
-$schema->storage->debugcb (undef);
-
-my @objs;
-#$artist = $rs->find(1);
-
$queries = 0;
-$schema->storage->debug(1);
-$schema->storage->debugcb ($debugcb);
+my @objs;
my $cds = $artist->cds;
my $tags = $cds->next->tags;
while( my $tag = $tags->next ) {
push @objs, $tag->id; #warn "tag: ", $tag->ID;
}
-is_deeply( \@objs, [ 2, 5, 8 ], 'third cd has correct tags' );
+is_deeply( [ sort @objs] , [ 2, 5, 8 ], 'third cd has correct tags' );
$tags = $cds->next->tags;
@objs = ();
cmp_ok (
$rs->count,
- '!=',
+ '>',
$rs->search ({}, {columns => ['year'], distinct => 1})->count,
'At least one year is the same in rs'
);
my $rs_year = $rs->get_column('year');
my $max_year = $rs->get_column(\'MAX (year)');
-is($rs_title->next, 'Spoonful of bees', "next okay");
+my @all_titles = $rs_title->all;
+cmp_ok(scalar @all_titles, '==', 5, "five titles returned");
+
+my @nexted_titles;
+while (my $r = $rs_title->next) {
+ push @nexted_titles, $r;
+}
+
+is_deeply (\@all_titles, \@nexted_titles, 'next works');
+
is_deeply( [ sort $rs_year->func('DISTINCT') ], [ 1997, 1998, 1999, 2001 ], "wantarray context okay");
ok ($max_year->next == $rs_year->max, q/get_column (\'FUNC') ok/);
-my @all = $rs_title->all;
-cmp_ok(scalar @all, '==', 5, "five titles returned");
-
cmp_ok($rs_year->max, '==', 2001, "max okay for year");
is($rs_title->min, 'Caterwaulin\' Blues', "min okay for title");
cmp_ok($rs_year->sum, '==', 9996, "three artists returned");
-$rs_year->reset;
-is($rs_year->next, 1999, "reset okay");
+my $rso_year = $rs->search({}, { order_by => 'cdid' })->get_column('year');
+is($rso_year->next, 1999, "reset okay");
-is($rs_year->first, 1999, "first okay");
+is($rso_year->first, 1999, "first okay");
warnings_exist (sub {
- is($rs_year->single, 1999, "single okay");
+ is($rso_year->single, 1999, "single okay");
}, qr/Query returned more than one row/, 'single warned');
# make sure joined/prefetched get_column of a PK dtrt
-
$rs->reset;
my $j_rs = $rs->search ({}, { join => 'tracks' })->get_column ('cdid');
is_deeply (
$rs->reset;
my $p_rs = $rs->search ({}, { prefetch => 'tracks' })->get_column ('cdid');
is_deeply (
- [ $p_rs->all ],
- [ $rs->get_column ('cdid')->all ],
+ [ sort $p_rs->all ],
+ [ sort $rs->get_column ('cdid')->all ],
'prefetch properly collapses amount of rows from get_column',
);
cmp_ok($rs3->count, '==', 15, "All cds for artist returned via count");
-my $rs4 = $schema->resultset("CD")->search({ 'artist.artistid' => '1' }, { join => ['tracks', 'artist'], prefetch => 'artist' });
+my $rs4 = $schema->resultset("CD")->search({ 'artist.artistid' => '1' }, {
+ join => ['tracks', 'artist'], prefetch => 'artist', order_by => 'me.cdid'
+});
my @rs4_results = $rs4->all;
is($rs4_results[0]->cdid, 1, "correct artist returned");
[2,2,undef,undef,undef,'Aran',undef]
];
my $data;
- lives_ok { $data = $admin->select('Employee')} 'can retrive data from database';
+ lives_ok { $data = $admin->select('Employee', undef, { order_by => 'employee_id' })} 'can retrive data from database';
is_deeply($data, $expected_data, 'DB matches whats expected');
$admin->delete('Employee', {name=>'Trout'});
# no fsync on commit
$dbh->do ('PRAGMA synchronous = OFF');
+ $dbh->do ('PRAGMA reverse_unordered_selects = ON')
+ if $ENV{DBICTEST_SQLITE_REVERSE_DEFAULT_ORDER};
+
# set a *DBI* disconnect callback, to make sure the physical SQLite
# file is still there (i.e. the test does not attempt to delete
# an open database, which fails on Win32)
# test both sides of a 1:(1|0)
{
for my $reldir ('might_have', 'belongs_to') {
- my $artist = $schema->resultset('Artist')->next;
+ my $artist = $schema->resultset('Artist')->find(1);
my $new_track = $schema->resultset('Track')->new ({
title => "$reldir: First track of latest cd",
# /
# Producer
lives_ok ( sub {
- my $artist = $schema->resultset('Artist')->first;
+ my $artist = $schema->resultset('Artist')->find(1);
my $cd = $schema->resultset('CD')->create ({
artist => $artist,
title => 'Music to code by at night',
is ($cd->title, 'Music to code by at night', 'Correct CD title');
is ($cd->tracks->count, 2, 'Two tracks on main CD');
- my ($t1, $t2) = $cd->tracks->all;
+ my ($t1, $t2) = sort { $a->id <=> $b->id } $cd->tracks->all;
is ($t1->title, 'Off by one again', 'Correct 1st track name');
is ($t1->cd_single, undef, 'No single for 1st track');
is ($t2->title, 'The dereferencer', 'Correct 2nd track name');
my $pref_rs = $schema->resultset('Owners')->search({}, {
rows => 3,
offset => 1,
+ order_by => 'name',
columns => 'name', # only the owner name, still prefetch all the books
prefetch => 'books',
});
FROM (
SELECT me.name, me.id
FROM owners me
+ ORDER BY name
LIMIT ?
OFFSET ?
) me
LEFT JOIN books books
ON books.owner = me.id
+ ORDER BY name
)',
[ [ { sqlt_datatype => "integer" } => 3 ], [ { sqlt_datatype => "integer" } => 1 ] ],
'Expected SQL on complex limited prefetch with non-selected join condition',
{ 'title' => 'me.title' }, # uniquiness for me
{ 'artist' => 'me.artist' }, # uniquiness for me
],
- order_by => [{ -desc => 'cds.year' }, { -desc => 'me.title'} ],
+ order_by => [{ -desc => 'cds.year' }, { -desc => 'me.title'}, 'tracks.title', 'tracks_2.title' ],
});
my $hri_rs = $rs->search({}, { result_class => 'DBIx::Class::ResultClass::HashRefInflator' });
result_class => 'DBIx::Class::ResultClass::HashRefInflator',
- order_by => [qw/tracks.position tracks.trackid producer.producerid/],
+ order_by => [qw/tracks.position tracks.trackid producer.producerid tracks_2.trackid artwork.cd_id/],
}
);
}
],
artwork_to_artist => [
- { artwork => {cd_id => 1 } },
+ { artwork => { cd_id => 1 } },
{ artwork => { cd_id => 2 } }
]
}
},
],
{
- order_by => 'me.cdid',
+ order_by => [qw(me.cdid cds.title)],
prefetch => { artist => 'cds' },
result_class => 'DBIx::Class::ResultClass::HashRefInflator',
},
$schema->storage->debug(1);
$rs = $schema->resultset('Tag')->search(
- {},
+ { 'me.tagid' => 1 },
{
prefetch => { cd => 'artist' }
}
$schema->storage->debugcb(sub { $queries++; });
-$cd = $schema->resultset('CD')->find(1, { prefetch => { cd_to_producer => 'producer' } });
+$cd = $schema->resultset('CD')->find(1, { prefetch => { cd_to_producer => 'producer' }, order_by => 'producer.producerid' });
is($cd->producers->first->name, 'Matt S Trout', 'many_to_many accessor ok');
$queries = 0;
-is($art_rs_pr->search_related('cds')->search_related('tracks')->first->title,
- 'Fowlin',
- 'chained has_many->has_many search_related ok'
- );
+is_deeply(
+ [ sort map { $_->title } $art_rs_pr->search_related('cds')->search_related('tracks')->all ],
+ [ 'Apiary', 'Beehind You', 'Boring Name', 'Boring Song', 'Fowlin', 'Howlin',
+ 'No More Ideas', 'Sad', 'Sticky Honey', 'Stripy', 'Stung with Success',
+ 'Suicidal', 'The Bees Knees', 'Under The Weather', 'Yowlin' ],
+ 'chained has_many->has_many search_related ok'
+);
is($queries, 0, 'chained search_related after has_many->has_many prefetch ran no queries');
# many_to_many helper tests
$cd = $schema->resultset("CD")->find(1);
-my @producers = $cd->producers();
+my @producers = $cd->producers(undef, { order_by => 'producerid'} );
is( $producers[0]->name, 'Matt S Trout', 'many_to_many ok' );
is( $cd->producers_sorted->next->name, 'Bob The Builder',
'sorted many_to_many ok' );
my $schema = DBICTest->init_schema();
my $sdebug = $schema->storage->debug;
-my $artist = $schema->resultset ('Artist')->first;
+my $artist = $schema->resultset ('Artist')->find(1);
my $genre = $schema->resultset ('Genre')
->create ({ name => 'par excellence' });
{ 'me.position' => 2 },
{
join => { cd => 'artist' },
- 'columns' => [ 'me.title', { 'artist.cdtitle' => 'cd.title' }, 'artist.name' ],
- order_by => 'artist.name',
+ columns => [ 'me.title', { 'artist.cdtitle' => 'cd.title' }, 'artist.name' ],
+ order_by => [ 'artist.name', { -desc => 'cd.cdid' }, 'me.trackid' ],
}
);
my $schema = DBICTest->init_schema();
-my $cd_rs = $schema->resultset("CD");
+my $cd_rs = $schema->resultset("CD")->search({ 'me.cdid' => 1 });
warnings_exist( sub {
my $cd = $cd_rs->search( undef, {
my $schema = DBICTest->init_schema();
-my $artist = $schema->resultset('Artist')->next;
+my $artist = $schema->resultset('Artist')->find(1);
is_deeply(
[ $artist->id, $artist->ident_condition, $artist->_storage_ident_condition ],