1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2 use DBIx::Class::Optional::Dependencies -skip_all_without => 'test_rdbms_db2';
13 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_DB2_${_}" } qw/DSN USER PASS/};
14 my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
16 my $name_sep = $schema->storage->_dbh_get_info('SQL_QUALIFIER_NAME_SEPARATOR');
18 my $dbh = $schema->storage->dbh;
20 # test RNO and name_sep detection
22 is $schema->storage->sql_maker->name_sep, $name_sep,
26 $dbh->selectrow_array(
27 "SELECT row_number() OVER (ORDER BY 1) FROM sysibm${name_sep}sysdummy1"
32 is $schema->storage->sql_maker->limit_dialect,
33 ($have_rno ? 'RowNumberOver' : 'FetchFirst'),
34 'limit_dialect detection';
36 eval { $dbh->do("DROP TABLE artist") };
38 $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);");
40 my $ars = $schema->resultset('Artist');
41 is ( $ars->count, 0, 'No rows at first' );
43 # test primary key handling
44 my $new = $ars->create({ name => 'foo' });
45 ok($new->artistid, "Auto-PK worked");
47 # test explicit key spec
48 $new = $ars->create ({ name => 'bar', artistid => 66 });
49 is($new->artistid, 66, 'Explicit PK worked');
50 $new->discard_changes;
51 is($new->artistid, 66, 'Explicit PK assigned');
57 push @pop, { name => "Artist_$_" };
59 $ars->populate (\@pop);
62 # test populate with explicit key
66 push @pop, { name => "Artist_expkey_$_", artistid => 100 + $_ };
68 $ars->populate (\@pop);
71 # count what we did so far
72 is ($ars->count, 6, 'Simple count works');
75 my $lim = $ars->search( {},
79 order_by => 'artistid'
82 is( $lim->count, 2, 'ROWS+OFFSET count ok' );
83 is( $lim->all, 2, 'Number of ->all objects matches count' );
85 # Limit with select-lock
87 local $TODO = "Seems we can't SELECT ... FOR ... on subqueries";
89 $schema->txn_do (sub {
91 $schema->resultset('Artist')->find({artistid => 1}, {for => 'update', rows => 1}),
92 'DBICTest::Schema::Artist',
95 } 'Limited FOR UPDATE select works';
100 is( $lim->next->artistid, 101, "iterator->next ok" );
101 is( $lim->next->artistid, 102, "iterator->next ok" );
102 is( $lim->next, undef, "next past end of resultset ok" );
104 # test FetchFirst limit dialect syntax
106 local $schema->storage->sql_maker->{limit_dialect} = 'FetchFirst';
108 my $lim = $ars->search({}, {
111 order_by => 'artistid',
114 is $lim->count, 3, 'fetch first limit count ok';
116 is $lim->all, 3, 'fetch first number of ->all objects matches count';
118 is $lim->next->artistid, 3, 'iterator->next ok';
119 is $lim->next->artistid, 66, 'iterator->next ok';
120 is $lim->next->artistid, 101, 'iterator->next ok';
121 is $lim->next, undef, 'iterator->next past end of resultset ok';
124 my $test_type_info = {
126 'data_type' => 'INTEGER',
131 'data_type' => 'VARCHAR',
136 'data_type' => 'CHAR',
141 'data_type' => 'INTEGER',
148 my $type_info = $schema->storage->columns_info_for('artist');
149 is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
155 my $dbh = eval { $schema->storage->_dbh };
156 $dbh->do("DROP TABLE artist") if $dbh;