Merge 'trunk' into 'DBIx-Class-current'
[dbsrgits/DBIx-Class-Historic.git] / t / run / 145db2.tl
CommitLineData
843f8ecd 1sub run_tests {
2my $schema = shift;
3
4my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_DB2_${_}" } qw/DSN USER PASS/};
5
6#warn "$dsn $user $pass";
7
8plan skip_all, 'Set $ENV{DBICTEST_DB2_DSN}, _USER and _PASS to run this test'
9 unless ($dsn && $user);
10
fc22fbac 11plan tests => 6;
843f8ecd 12
13DBICTest::Schema->compose_connection('DB2Test' => $dsn, $user, $pass);
14
15my $dbh = DB2Test->schema->storage->dbh;
16
be194671 17$dbh->do("DROP TABLE artist", { RaiseError => 0, PrintError => 0 });
843f8ecd 18
19$dbh->do("CREATE TABLE artist (artistid INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), name VARCHAR(255), charfield CHAR(10));");
20
21#'dbi:mysql:host=localhost;database=dbic_test', 'dbic_test', '');
22
23DB2Test::Artist->load_components('PK::Auto');
24
25# test primary key handling
26my $new = DB2Test::Artist->create({ name => 'foo' });
27ok($new->artistid, "Auto-PK worked");
28
29# test LIMIT support
30for (1..6) {
31 DB2Test::Artist->create({ name => 'Artist ' . $_ });
32}
33my $it = DB2Test::Artist->search( {},
34 { rows => 3,
35 order_by => 'artistid'
36 }
37);
38is( $it->count, 3, "LIMIT count ok" );
fc22fbac 39is( $it->next->name, "foo", "iterator->next ok" );
843f8ecd 40$it->next;
fc22fbac 41is( $it->next->name, "Artist 2", "iterator->next ok" );
843f8ecd 42is( $it->next, undef, "next past end of resultset ok" );
43
44my $test_type_info = {
45 'artistid' => {
46 'data_type' => 'INTEGER',
47 'is_nullable' => 0,
fc22fbac 48 'size' => 10
843f8ecd 49 },
50 'name' => {
51 'data_type' => 'VARCHAR',
52 'is_nullable' => 1,
53 'size' => 255
54 },
55 'charfield' => {
fc22fbac 56 'data_type' => 'CHAR',
843f8ecd 57 'is_nullable' => 1,
58 'size' => 10
59 },
60};
61
62
63my $type_info = DB2Test->schema->storage->columns_info_for('artist');
64is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
65
66
67
68# clean up our mess
69$dbh->do("DROP TABLE artist");
70
71}
72
731;