7 use DBIx::Class::Optional::Dependencies ();
11 plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_rdbms_db2')
12 unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_rdbms_db2');
14 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_DB2_${_}" } qw/DSN USER PASS/};
16 #warn "$dsn $user $pass";
18 plan skip_all => 'Set $ENV{DBICTEST_DB2_DSN}, _USER and _PASS to run this test'
19 unless ($dsn && $user);
21 my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
23 my $dbh = $schema->storage->dbh;
25 # test RNO and name_sep detection
26 my $name_sep = $dbh->get_info(41);
28 is $schema->storage->sql_maker->name_sep, $name_sep,
32 $dbh->selectrow_array(
33 "SELECT row_number() OVER (ORDER BY 1) FROM sysibm${name_sep}sysdummy1"
38 is $schema->storage->sql_maker->limit_dialect,
39 ($have_rno ? 'RowNumberOver' : 'FetchFirst'),
40 'limit_dialect detection';
42 eval { $dbh->do("DROP TABLE artist") };
44 $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);");
46 my $ars = $schema->resultset('Artist');
47 is ( $ars->count, 0, 'No rows at first' );
49 # test primary key handling
50 my $new = $ars->create({ name => 'foo' });
51 ok($new->artistid, "Auto-PK worked");
53 # test explicit key spec
54 $new = $ars->create ({ name => 'bar', artistid => 66 });
55 is($new->artistid, 66, 'Explicit PK worked');
56 $new->discard_changes;
57 is($new->artistid, 66, 'Explicit PK assigned');
63 push @pop, { name => "Artist_$_" };
65 $ars->populate (\@pop);
68 # test populate with explicit key
72 push @pop, { name => "Artist_expkey_$_", artistid => 100 + $_ };
74 $ars->populate (\@pop);
77 # count what we did so far
78 is ($ars->count, 6, 'Simple count works');
81 my $lim = $ars->search( {},
85 order_by => 'artistid'
88 is( $lim->count, 2, 'ROWS+OFFSET count ok' );
89 is( $lim->all, 2, 'Number of ->all objects matches count' );
91 # Limit with select-lock
93 local $TODO = "Seems we can't SELECT ... FOR ... on subqueries";
95 $schema->txn_do (sub {
97 $schema->resultset('Artist')->find({artistid => 1}, {for => 'update', rows => 1}),
98 'DBICTest::Schema::Artist',
101 } 'Limited FOR UPDATE select works';
106 is( $lim->next->artistid, 101, "iterator->next ok" );
107 is( $lim->next->artistid, 102, "iterator->next ok" );
108 is( $lim->next, undef, "next past end of resultset ok" );
110 # test FetchFirst limit dialect syntax
112 local $schema->storage->sql_maker->{limit_dialect} = 'FetchFirst';
114 my $lim = $ars->search({}, {
117 order_by => 'artistid',
120 is $lim->count, 3, 'fetch first limit count ok';
122 is $lim->all, 3, 'fetch first number of ->all objects matches count';
124 is $lim->next->artistid, 3, 'iterator->next ok';
125 is $lim->next->artistid, 66, 'iterator->next ok';
126 is $lim->next->artistid, 101, 'iterator->next ok';
127 is $lim->next, undef, 'iterator->next past end of resultset ok';
130 my $test_type_info = {
132 'data_type' => 'INTEGER',
137 'data_type' => 'VARCHAR',
142 'data_type' => 'CHAR',
147 'data_type' => 'INTEGER',
154 my $type_info = $schema->storage->columns_info_for('artist');
155 is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
161 my $dbh = eval { $schema->storage->_dbh };
162 $dbh->do("DROP TABLE artist") if $dbh;