10 my $schema = DBICTest->init_schema();
12 my $orig_debug = $schema->storage->debug;
17 eval "use DBD::SQLite";
19 ? ( skip_all => 'needs DBD::SQLite for testing' )
23 # figure out if we've got a version of sqlite that is older than 3.2.6, in
24 # which case COUNT(DISTINCT()) doesn't work
25 my $is_broken_sqlite = 0;
26 my ($sqlite_major_ver,$sqlite_minor_ver,$sqlite_patch_ver) =
27 split /\./, $schema->storage->dbh->get_info(18);
28 if( $schema->storage->dbh->get_info(17) eq 'SQLite' &&
29 ( ($sqlite_major_ver < 3) ||
30 ($sqlite_major_ver == 3 && $sqlite_minor_ver < 2) ||
31 ($sqlite_major_ver == 3 && $sqlite_minor_ver == 2 && $sqlite_patch_ver < 6) ) ) {
32 $is_broken_sqlite = 1;
35 # A search() with prefetch seems to pollute an already joined resultset
36 # in a way that offsets future joins (adapted from a test case by Debolaz)
40 # test a real-life case - rs is obtained by an implicit m2m join
41 $cd_rs = $schema->resultset ('Producer')->first->cds;
42 $attrs = Dumper $cd_rs->{attrs};
44 $cd_rs->search ({})->all;
45 is (Dumper ($cd_rs->{attrs}), $attrs, 'Resultset attributes preserved after a simple search');
48 $cd_rs->search ({'artist.artistid' => 1}, { prefetch => 'artist' })->all;
49 is (Dumper ($cd_rs->{attrs}), $attrs, 'Resultset attributes preserved after search with prefetch');
50 }, 'first prefetching search ok');
53 $cd_rs->search ({'artist.artistid' => 1}, { prefetch => 'artist' })->all;
54 is (Dumper ($cd_rs->{attrs}), $attrs, 'Resultset attributes preserved after another search with prefetch')
55 }, 'second prefetching search ok');
58 # test a regular rs with an empty seen_join injected - it should still work!
59 $cd_rs = $schema->resultset ('CD');
60 $cd_rs->{attrs}{seen_join} = {};
61 $attrs = Dumper $cd_rs->{attrs};
63 $cd_rs->search ({})->all;
64 is (Dumper ($cd_rs->{attrs}), $attrs, 'Resultset attributes preserved after a simple search');
67 $cd_rs->search ({'artist.artistid' => 1}, { prefetch => 'artist' })->all;
68 is (Dumper ($cd_rs->{attrs}), $attrs, 'Resultset attributes preserved after search with prefetch');
69 }, 'first prefetching search ok');
72 $cd_rs->search ({'artist.artistid' => 1}, { prefetch => 'artist' })->all;
73 is (Dumper ($cd_rs->{attrs}), $attrs, 'Resultset attributes preserved after another search with prefetch')
74 }, 'second prefetching search ok');