ac6cd479fce00ad62cbd2720c2ccfbd39f782ecc
[dbsrgits/DBIx-Class.git] / t / run / 146db2_400.tl
1 sub run_tests {
2 my $schema = shift;
3
4 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_DB2_400_${_}" } qw/DSN USER PASS/};
5
6 #warn "$dsn $user $pass";
7
8 # Probably best to pass the DBQ option in the DSN to specify a specific
9 # libray.  Something like:
10 # DBICTEST_DB2_400_DSN='dbi:ODBC:dsn=MyAS400;DBQ=MYLIB'
11 plan skip_all, 'Set $ENV{DBICTEST_DB2_400_DSN}, _USER and _PASS to run this test'
12   unless ($dsn && $user);
13
14 plan tests => 6;
15
16 DBICTest::Schema->compose_connection('DB2Test' => $dsn, $user, $pass);
17
18 my $dbh = DB2Test->schema->storage->dbh;
19
20 $dbh->do("DROP TABLE artist", { RaiseError => 0, PrintError => 0 });
21
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))");
23
24 DB2Test::Artist->load_components('PK::Auto');
25
26 # test primary key handling
27 my $new = DB2Test::Artist->create({ name => 'foo' });
28 ok($new->artistid, "Auto-PK worked");
29
30 # test LIMIT support
31 for (1..6) {
32     DB2Test::Artist->create({ name => 'Artist ' . $_ });
33 }
34 my $it = DB2Test::Artist->search( {},
35     { rows => 3,
36       order_by => 'artistid'
37       }
38 );
39 is( $it->count, 3, "LIMIT count ok" );
40 is( $it->next->name, "foo", "iterator->next ok" );
41 $it->next;
42 is( $it->next->name, "Artist 2", "iterator->next ok" );
43 is( $it->next, undef, "next past end of resultset ok" );
44
45 my $test_type_info = {
46     'artistid' => {
47         'data_type' => 'INTEGER',
48         'is_nullable' => 0,
49         'size' => 10
50     },
51     'name' => {
52         'data_type' => 'VARCHAR',
53         'is_nullable' => 1,
54         'size' => 255
55     },
56     'charfield' => {
57         'data_type' => 'CHAR',
58         'is_nullable' => 1,
59         'size' => 10 
60     },
61 };
62
63
64 my $type_info = DB2Test->schema->storage->columns_info_for('artist');
65 is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
66
67
68
69 # clean up our mess
70 $dbh->do("DROP TABLE artist");
71
72 }
73
74 1;