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);
51 no warnings 'redefine';
52 my $old_sth_new=\&DBIx::Class::Storage::DBI::Pg::Sth::new;
53 *DBIx::Class::Storage::DBI::Pg::Sth::new=sub {
54 ++$called;$page_size=$_[4];
60 return unless $schema;
61 drop_test_schema($schema);
64 my $start_id = 'populateXaaaaaa';
69 $schema->populate('Artist', [ [ qw/artistid name/ ], map { [ ($_ + $offset) => $start_id++ ] } ( 1 .. $rows ) ] );
70 is ($called,0,'Pg::Sth not created for insert');
72 $schema->resultset ('Artist')->search ({ name => { -like => 'populateX%' } })->count,
74 'populate created correct number of rows with massive AoA bulk insert',
79 my $rs=$schema->resultset('Artist')->search({});
81 $count++ while $rs->next;
82 is($count,$rows,'get all the rows (loop)');
83 is($called,1,'Pg::Sth called once per rs');
84 is($page_size,1000,'default page size used');
89 my $rs=$schema->resultset('Artist')->search({},{cursor_page_size=>10});
91 is($called,1,'Pg::Sth called again per rs');
92 is($page_size,10,'page size from attrs used');
97 my $rs=$schema->resultset('Artist')->search({});
98 $schema->storage->cursor_page_size(20);
100 is($called,1,'Pg::Sth called again per rs');
101 is($page_size,20,'page size from storage used');
102 $schema->storage->cursor_page_size(undef);
107 my $rs=$schema->resultset('Artist')->search({});
109 is(scalar(@rows),$rows,'get all the rows (all)');
110 is($called,1,'Pg::Sth called again per rs');
111 is($page_size,1000,'default page size used again');
116 my $rs=$schema->resultset('Artist')->search({});
117 $schema->storage->set_use_dbms_capability('server_cursors',0);
119 is(scalar(@rows),$rows,'get all the rows (all)');
120 is($called,0,'Pg::Sth *not* called');
121 $schema->storage->set_use_dbms_capability('server_cursors',1);
126 my $rs=$schema->resultset('Artist')->search({},{server_cursors=>0});
128 is(scalar(@rows),$rows,'get all the rows (all)');
129 is($called,0,'Pg::Sth *not* called');