cleanup, moved Pg::Sth to separate file
[dbsrgits/DBIx-Class.git] / t / 72pg_cursors.t
CommitLineData
8c194608 1#!perl
2use strict;
3use warnings;
4
5use Test::More;
6use lib qw(t/lib);
7use DBICTest;
8use Time::HiRes qw(gettimeofday tv_interval);
9
10my ($dsn, $dbuser, $dbpass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/};
11
12plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test'
13 unless ($dsn && $dbuser);
14
15plan tests => 3;
16
17sub create_test_schema {
18 my ($schema)=@_;
19 $schema->storage->dbh_do(
20 sub {
21 my (undef,$dbh)=@_;
22 local $dbh->{Warn} = 0;
23 $dbh->do(q[
24 CREATE TABLE artist
25 (
26 artistid serial NOT NULL PRIMARY KEY,
27 name varchar(100),
28 rank integer,
29 charfield char(10)
30 );
31 ],{ RaiseError => 0, PrintError => 0 });
32 });
33}
34
35sub drop_test_schema {
36 my ($schema)=@_;
37 $schema->storage->dbh_do(
38 sub {
39 my (undef,$dbh)=@_;
40 local $dbh->{Warn} = 0;
41 eval { $dbh->do('DROP TABLE IF EXISTS artist') };
42 eval { $dbh->do('DROP SEQUENCE public.artist_artistid_seq') };
43 });
44}
45
46# copied from 100populate.t
47
48my $schema = DBICTest::Schema->connection($dsn, $dbuser, $dbpass, { AutoCommit => 1 });
49drop_test_schema($schema);create_test_schema($schema);
50
51END {
52 return unless $schema;
53 drop_test_schema($schema);
54}
55
56my $start_id = 'populateXaaaaaa';
57my $rows=1e4;
58my $offset = 3;
59
60$schema->populate('Artist', [ [ qw/artistid name/ ], map { [ ($_ + $offset) => $start_id++ ] } ( 1 .. $rows ) ] );
61is (
62 $schema->resultset ('Artist')->search ({ name => { -like => 'populateX%' } })->count,
63 $rows,
64 'populate created correct number of rows with massive AoA bulk insert',
65);
66
67{
68 my $rs=$schema->resultset('Artist')->search({});
69 my $count=0;
70 my $t0=[gettimeofday];
71 $count++ while $rs->next;
72 is($count,$rows,'get all the rows (loop)');
73 diag('Time for all(loop): '.tv_interval($t0));
74}
75
76{
77 my $rs=$schema->resultset('Artist')->search({});
78 my $t0=[gettimeofday];
79 $rs->first;
80 diag('Time for first: '.tv_interval($t0));
81}
82
83{
84 my $rs=$schema->resultset('Artist')->search({});
85 my $t0=[gettimeofday];
86 my @rows=$rs->all;
87 is(scalar(@rows),$rows,'get all the rows (all)');
88 diag('Time for all: '.tv_interval($t0));
89}