Commit | Line | Data |
cb551b07 |
1 | use DBIx::Class::Optional::Dependencies -skip_all_without => 'test_rdbms_db2_400'; |
2 | |
70350518 |
3 | use strict; |
68de9438 |
4 | use warnings; |
70350518 |
5 | |
6 | use Test::More; |
199fbc45 |
7 | use DBIx::Class::Optional::Dependencies (); |
70350518 |
8 | use lib qw(t/lib); |
9 | use DBICTest; |
8e14d52c |
10 | |
8e14d52c |
11 | # Probably best to pass the DBQ option in the DSN to specify a specific |
12 | # libray. Something like: |
13 | # DBICTEST_DB2_400_DSN='dbi:ODBC:dsn=MyAS400;DBQ=MYLIB' |
cb551b07 |
14 | my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_DB2_400_${_}" } qw/DSN USER PASS/}; |
8e14d52c |
15 | |
16 | plan tests => 6; |
17 | |
3ff5b740 |
18 | my $schema = DBICTest::Schema->connect($dsn, $user, $pass); |
8e14d52c |
19 | |
3ff5b740 |
20 | my $dbh = $schema->storage->dbh; |
8e14d52c |
21 | |
c1cac633 |
22 | eval { $dbh->do("DROP TABLE artist") }; |
8e14d52c |
23 | |
a466dec9 |
24 | $dbh->do(<<''); |
25 | CREATE TABLE artist ( |
26 | artistid INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), |
27 | name VARCHAR(255), |
28 | rank INTEGER default 13 not null, |
29 | charfield CHAR(10) |
30 | ) |
8e14d52c |
31 | |
3ff5b740 |
32 | # Just to test loading, already in Core |
33 | $schema->class('Artist')->load_components('PK::Auto'); |
8e14d52c |
34 | |
35 | # test primary key handling |
3ff5b740 |
36 | my $new = $schema->resultset('Artist')->create({ name => 'foo' }); |
8e14d52c |
37 | ok($new->artistid, "Auto-PK worked"); |
38 | |
39 | # test LIMIT support |
40 | for (1..6) { |
3ff5b740 |
41 | $schema->resultset('Artist')->create({ name => 'Artist ' . $_ }); |
8e14d52c |
42 | } |
3ff5b740 |
43 | my $it = $schema->resultset('Artist')->search( {}, |
8e14d52c |
44 | { rows => 3, |
45 | order_by => 'artistid' |
46 | } |
47 | ); |
48 | is( $it->count, 3, "LIMIT count ok" ); |
49 | is( $it->next->name, "foo", "iterator->next ok" ); |
50 | $it->next; |
51 | is( $it->next->name, "Artist 2", "iterator->next ok" ); |
52 | is( $it->next, undef, "next past end of resultset ok" ); |
53 | |
54 | my $test_type_info = { |
55 | 'artistid' => { |
56 | 'data_type' => 'INTEGER', |
57 | 'is_nullable' => 0, |
58 | 'size' => 10 |
59 | }, |
60 | 'name' => { |
61 | 'data_type' => 'VARCHAR', |
62 | 'is_nullable' => 1, |
63 | 'size' => 255 |
64 | }, |
a466dec9 |
65 | 'rank' => { |
66 | 'data_type' => 'INTEGER', |
67 | 'is_nullable' => 0, |
68 | 'size' => 10, |
69 | }, |
8e14d52c |
70 | 'charfield' => { |
71 | 'data_type' => 'CHAR', |
72 | 'is_nullable' => 1, |
8273e845 |
73 | 'size' => 10 |
8e14d52c |
74 | }, |
75 | }; |
76 | |
77 | |
3ff5b740 |
78 | my $type_info = $schema->storage->columns_info_for('artist'); |
8e14d52c |
79 | is_deeply($type_info, $test_type_info, 'columns_info_for - column data types'); |
80 | |
8e14d52c |
81 | # clean up our mess |
3ff5b740 |
82 | END { |
65d35121 |
83 | my $dbh = eval { $schema->storage->_dbh }; |
84 | $dbh->do("DROP TABLE artist") if $dbh; |
85 | undef $schema; |
3ff5b740 |
86 | } |