9 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_DB2_${_}" } qw/DSN USER PASS/};
11 #warn "$dsn $user $pass";
13 plan skip_all => 'Set $ENV{DBICTEST_DB2_DSN}, _USER and _PASS to run this test'
14 unless ($dsn && $user);
16 my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
18 my $dbh = $schema->storage->dbh;
20 eval { $dbh->do("DROP TABLE artist") };
22 $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);");
24 my $ars = $schema->resultset('Artist');
25 is ( $ars->count, 0, 'No rows at first' );
27 # test primary key handling
28 my $new = $ars->create({ name => 'foo' });
29 ok($new->artistid, "Auto-PK worked");
31 # test explicit key spec
32 $new = $ars->create ({ name => 'bar', artistid => 66 });
33 is($new->artistid, 66, 'Explicit PK worked');
34 $new->discard_changes;
35 is($new->artistid, 66, 'Explicit PK assigned');
41 push @pop, { name => "Artist_$_" };
43 $ars->populate (\@pop);
46 # test populate with explicit key
50 push @pop, { name => "Artist_expkey_$_", artistid => 100 + $_ };
52 $ars->populate (\@pop);
55 # count what we did so far
56 is ($ars->count, 6, 'Simple count works');
59 my $lim = $ars->search( {},
63 order_by => 'artistid'
66 is( $lim->count, 2, 'ROWS+OFFSET count ok' );
67 is( $lim->all, 2, 'Number of ->all objects matches count' );
71 is( $lim->next->artistid, 101, "iterator->next ok" );
72 is( $lim->next->artistid, 102, "iterator->next ok" );
73 is( $lim->next, undef, "next past end of resultset ok" );
76 my $test_type_info = {
78 'data_type' => 'INTEGER',
83 'data_type' => 'VARCHAR',
88 'data_type' => 'CHAR',
93 'data_type' => 'INTEGER',
100 my $type_info = $schema->storage->columns_info_for('artist');
101 is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
107 my $dbh = eval { $schema->storage->_dbh };
108 $dbh->do("DROP TABLE artist") if $dbh;