10 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_DB2_${_}" } qw/DSN USER PASS/};
12 #warn "$dsn $user $pass";
14 plan skip_all => 'Set $ENV{DBICTEST_DB2_DSN}, _USER and _PASS to run this test'
15 unless ($dsn && $user);
17 my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
19 my $dbh = $schema->storage->dbh;
21 # test RNO and name_sep detection
22 my $name_sep = $dbh->get_info(41);
24 is $schema->storage->sql_maker->name_sep, $name_sep,
28 $dbh->selectrow_array(
29 "SELECT row_number() OVER (ORDER BY 1) FROM sysibm${name_sep}sysdummy1"
34 is $schema->storage->sql_maker->limit_dialect,
35 ($have_rno ? 'RowNumberOver' : 'FetchFirst'),
36 'limit_dialect detection';
38 eval { $dbh->do("DROP TABLE artist") };
40 $dbh->do("CREATE TABLE artist (artistid INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), name VARCHAR(255), charfield CHAR(10), rank INTEGER DEFAULT 13);");
42 my $ars = $schema->resultset('Artist');
43 is ( $ars->count, 0, 'No rows at first' );
45 # test primary key handling
46 my $new = $ars->create({ name => 'foo' });
47 ok($new->artistid, "Auto-PK worked");
49 # test explicit key spec
50 $new = $ars->create ({ name => 'bar', artistid => 66 });
51 is($new->artistid, 66, 'Explicit PK worked');
52 $new->discard_changes;
53 is($new->artistid, 66, 'Explicit PK assigned');
59 push @pop, { name => "Artist_$_" };
61 $ars->populate (\@pop);
64 # test populate with explicit key
68 push @pop, { name => "Artist_expkey_$_", artistid => 100 + $_ };
70 $ars->populate (\@pop);
73 # count what we did so far
74 is ($ars->count, 6, 'Simple count works');
77 my $lim = $ars->search( {},
81 order_by => 'artistid'
84 is( $lim->count, 2, 'ROWS+OFFSET count ok' );
85 is( $lim->all, 2, 'Number of ->all objects matches count' );
87 # Limit with select-lock
89 local $TODO = "Seems we can't SELECT ... FOR ... on subqueries";
91 $schema->txn_do (sub {
93 $schema->resultset('Artist')->find({artistid => 1}, {for => 'update', rows => 1}),
94 'DBICTest::Schema::Artist',
97 } 'Limited FOR UPDATE select works';
102 is( $lim->next->artistid, 101, "iterator->next ok" );
103 is( $lim->next->artistid, 102, "iterator->next ok" );
104 is( $lim->next, undef, "next past end of resultset ok" );
106 # test FetchFirst limit dialect syntax
108 local $schema->storage->sql_maker->{limit_dialect} = 'FetchFirst';
110 my $lim = $ars->search({}, {
113 order_by => 'artistid',
116 is $lim->count, 3, 'fetch first limit count ok';
118 is $lim->all, 3, 'fetch first number of ->all objects matches count';
120 is $lim->next->artistid, 3, 'iterator->next ok';
121 is $lim->next->artistid, 66, 'iterator->next ok';
122 is $lim->next->artistid, 101, 'iterator->next ok';
123 is $lim->next, undef, 'iterator->next past end of resultset ok';
126 my $test_type_info = {
128 'data_type' => 'INTEGER',
133 'data_type' => 'VARCHAR',
138 'data_type' => 'CHAR',
143 'data_type' => 'INTEGER',
150 my $type_info = $schema->storage->columns_info_for('artist');
151 is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
157 my $dbh = eval { $schema->storage->_dbh };
158 $dbh->do("DROP TABLE artist") if $dbh;