9 my ($dsn, $dbuser, $dbpass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/};
11 plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test'
12 unless ($dsn && $dbuser);
16 sub create_test_schema {
18 $schema->storage->dbh_do(
21 local $dbh->{Warn} = 0;
25 artistid serial NOT NULL PRIMARY KEY,
30 ],{ RaiseError => 0, PrintError => 0 });
34 sub drop_test_schema {
36 $schema->storage->dbh_do(
39 local $dbh->{Warn} = 0;
40 eval { $dbh->do('DROP TABLE IF EXISTS artist') };
41 eval { $dbh->do('DROP SEQUENCE public.artist_artistid_seq') };
45 my $schema = DBICTest::Schema->connection($dsn, $dbuser, $dbpass, { AutoCommit => 1 });
46 $schema->storage->set_use_dbms_capability('server_cursors',1);
47 drop_test_schema($schema);create_test_schema($schema);
49 my ($called,$page_size)=(0,0);
50 my $old_sth_new=\&DBIx::Class::Storage::DBI::Pg::Sth::new;
51 *DBIx::Class::Storage::DBI::Pg::Sth::new=sub {
52 ++$called;$page_size=$_[4];
57 return unless $schema;
58 drop_test_schema($schema);
61 my $start_id = 'populateXaaaaaa';
66 $schema->populate('Artist', [ [ qw/artistid name/ ], map { [ ($_ + $offset) => $start_id++ ] } ( 1 .. $rows ) ] );
67 is ($called,0,'Pg::Sth not created for insert');
69 $schema->resultset ('Artist')->search ({ name => { -like => 'populateX%' } })->count,
71 'populate created correct number of rows with massive AoA bulk insert',
76 my $rs=$schema->resultset('Artist')->search({});
78 $count++ while $rs->next;
79 is($count,$rows,'get all the rows (loop)');
80 is($called,1,'Pg::Sth called once per rs');
81 is($page_size,1000,'default page size used');
86 my $rs=$schema->resultset('Artist')->search({},{cursor_page_size=>10});
88 is($called,1,'Pg::Sth called again per rs');
89 is($page_size,10,'page size from attrs used');
94 my $rs=$schema->resultset('Artist')->search({});
95 $schema->storage->cursor_page_size(20);
97 is($called,1,'Pg::Sth called again per rs');
98 is($page_size,20,'page size from storage used');
99 $schema->storage->cursor_page_size(undef);
104 my $rs=$schema->resultset('Artist')->search({});
106 is(scalar(@rows),$rows,'get all the rows (all)');
107 is($called,1,'Pg::Sth called again per rs');
108 is($page_size,1000,'default page size used again');
113 my $rs=$schema->resultset('Artist')->search({},{server_cursors=>0});
115 is(scalar(@rows),$rows,'get all the rows (all)');
116 is($called,0,'Pg::Sth *not* called');