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 $name_sep = $schema->storage->_dbh_get_info('SQL_QUALIFIER_NAME_SEPARATOR');
25 my $dbh = $schema->storage->dbh;
27 # test RNO and name_sep detection
29 is $schema->storage->sql_maker->name_sep, $name_sep,
33 $dbh->selectrow_array(
34 "SELECT row_number() OVER (ORDER BY 1) FROM sysibm${name_sep}sysdummy1"
39 is $schema->storage->sql_maker->limit_dialect,
40 ($have_rno ? 'RowNumberOver' : 'FetchFirst'),
41 'limit_dialect detection';
43 eval { $dbh->do("DROP TABLE artist") };
45 $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);");
47 my $ars = $schema->resultset('Artist');
48 is ( $ars->count, 0, 'No rows at first' );
50 # test primary key handling
51 my $new = $ars->create({ name => 'foo' });
52 ok($new->artistid, "Auto-PK worked");
54 # test explicit key spec
55 $new = $ars->create ({ name => 'bar', artistid => 66 });
56 is($new->artistid, 66, 'Explicit PK worked');
57 $new->discard_changes;
58 is($new->artistid, 66, 'Explicit PK assigned');
64 push @pop, { name => "Artist_$_" };
66 $ars->populate (\@pop);
69 # test populate with explicit key
73 push @pop, { name => "Artist_expkey_$_", artistid => 100 + $_ };
75 $ars->populate (\@pop);
78 # count what we did so far
79 is ($ars->count, 6, 'Simple count works');
82 my $lim = $ars->search( {},
86 order_by => 'artistid'
89 is( $lim->count, 2, 'ROWS+OFFSET count ok' );
90 is( $lim->all, 2, 'Number of ->all objects matches count' );
92 # Limit with select-lock
94 local $TODO = "Seems we can't SELECT ... FOR ... on subqueries";
96 $schema->txn_do (sub {
98 $schema->resultset('Artist')->find({artistid => 1}, {for => 'update', rows => 1}),
99 'DBICTest::Schema::Artist',
102 } 'Limited FOR UPDATE select works';
107 is( $lim->next->artistid, 101, "iterator->next ok" );
108 is( $lim->next->artistid, 102, "iterator->next ok" );
109 is( $lim->next, undef, "next past end of resultset ok" );
111 # test FetchFirst limit dialect syntax
113 local $schema->storage->sql_maker->{limit_dialect} = 'FetchFirst';
115 my $lim = $ars->search({}, {
118 order_by => 'artistid',
121 is $lim->count, 3, 'fetch first limit count ok';
123 is $lim->all, 3, 'fetch first number of ->all objects matches count';
125 is $lim->next->artistid, 3, 'iterator->next ok';
126 is $lim->next->artistid, 66, 'iterator->next ok';
127 is $lim->next->artistid, 101, 'iterator->next ok';
128 is $lim->next, undef, 'iterator->next past end of resultset ok';
131 my $test_type_info = {
133 'data_type' => 'INTEGER',
138 'data_type' => 'VARCHAR',
143 'data_type' => 'CHAR',
148 'data_type' => 'INTEGER',
155 my $type_info = $schema->storage->columns_info_for('artist');
156 is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
162 my $dbh = eval { $schema->storage->_dbh };
163 $dbh->do("DROP TABLE artist") if $dbh;