1 use DBIx::Class::Optional::Dependencies -skip_all_without => 'test_rdbms_db2';
12 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_DB2_${_}" } qw/DSN USER PASS/};
13 my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
15 my $name_sep = $schema->storage->_dbh_get_info('SQL_QUALIFIER_NAME_SEPARATOR');
17 my $dbh = $schema->storage->dbh;
19 # test RNO and name_sep detection
21 is $schema->storage->sql_maker->name_sep, $name_sep,
25 $dbh->selectrow_array(
26 "SELECT row_number() OVER (ORDER BY 1) FROM sysibm${name_sep}sysdummy1"
31 is $schema->storage->sql_maker->limit_dialect,
32 ($have_rno ? 'RowNumberOver' : 'FetchFirst'),
33 'limit_dialect detection';
35 eval { $dbh->do("DROP TABLE artist") };
37 $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);");
39 my $ars = $schema->resultset('Artist');
40 is ( $ars->count, 0, 'No rows at first' );
42 # test primary key handling
43 my $new = $ars->create({ name => 'foo' });
44 ok($new->artistid, "Auto-PK worked");
46 # test explicit key spec
47 $new = $ars->create ({ name => 'bar', artistid => 66 });
48 is($new->artistid, 66, 'Explicit PK worked');
49 $new->discard_changes;
50 is($new->artistid, 66, 'Explicit PK assigned');
56 push @pop, { name => "Artist_$_" };
58 $ars->populate (\@pop);
61 # test populate with explicit key
65 push @pop, { name => "Artist_expkey_$_", artistid => 100 + $_ };
67 $ars->populate (\@pop);
70 # count what we did so far
71 is ($ars->count, 6, 'Simple count works');
74 my $lim = $ars->search( {},
78 order_by => 'artistid'
81 is( $lim->count, 2, 'ROWS+OFFSET count ok' );
82 is( $lim->all, 2, 'Number of ->all objects matches count' );
84 # Limit with select-lock
86 local $TODO = "Seems we can't SELECT ... FOR ... on subqueries";
88 $schema->txn_do (sub {
90 $schema->resultset('Artist')->find({artistid => 1}, {for => 'update', rows => 1}),
91 'DBICTest::Schema::Artist',
94 } 'Limited FOR UPDATE select works';
99 is( $lim->next->artistid, 101, "iterator->next ok" );
100 is( $lim->next->artistid, 102, "iterator->next ok" );
101 is( $lim->next, undef, "next past end of resultset ok" );
103 # test FetchFirst limit dialect syntax
105 local $schema->storage->sql_maker->{limit_dialect} = 'FetchFirst';
107 my $lim = $ars->search({}, {
110 order_by => 'artistid',
113 is $lim->count, 3, 'fetch first limit count ok';
115 is $lim->all, 3, 'fetch first number of ->all objects matches count';
117 is $lim->next->artistid, 3, 'iterator->next ok';
118 is $lim->next->artistid, 66, 'iterator->next ok';
119 is $lim->next->artistid, 101, 'iterator->next ok';
120 is $lim->next, undef, 'iterator->next past end of resultset ok';
123 my $test_type_info = {
125 'data_type' => 'INTEGER',
130 'data_type' => 'VARCHAR',
135 'data_type' => 'CHAR',
140 'data_type' => 'INTEGER',
147 my $type_info = $schema->storage->columns_info_for('artist');
148 is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
154 my $dbh = eval { $schema->storage->_dbh };
155 $dbh->do("DROP TABLE artist") if $dbh;