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