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 | |
2c2bc4e5 |
24 | require DBICTest::Schema; |
3ff5b740 |
25 | my $schema = DBICTest::Schema->connect($dsn, $user, $pass); |
8e14d52c |
26 | |
3ff5b740 |
27 | my $dbh = $schema->storage->dbh; |
8e14d52c |
28 | |
c1cac633 |
29 | eval { $dbh->do("DROP TABLE artist") }; |
8e14d52c |
30 | |
a466dec9 |
31 | $dbh->do(<<''); |
32 | CREATE TABLE artist ( |
33 | artistid INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), |
34 | name VARCHAR(255), |
35 | rank INTEGER default 13 not null, |
36 | charfield CHAR(10) |
37 | ) |
8e14d52c |
38 | |
3ff5b740 |
39 | # Just to test loading, already in Core |
40 | $schema->class('Artist')->load_components('PK::Auto'); |
8e14d52c |
41 | |
42 | # test primary key handling |
3ff5b740 |
43 | my $new = $schema->resultset('Artist')->create({ name => 'foo' }); |
8e14d52c |
44 | ok($new->artistid, "Auto-PK worked"); |
45 | |
46 | # test LIMIT support |
47 | for (1..6) { |
3ff5b740 |
48 | $schema->resultset('Artist')->create({ name => 'Artist ' . $_ }); |
8e14d52c |
49 | } |
3ff5b740 |
50 | my $it = $schema->resultset('Artist')->search( {}, |
8e14d52c |
51 | { rows => 3, |
52 | order_by => 'artistid' |
53 | } |
54 | ); |
55 | is( $it->count, 3, "LIMIT count ok" ); |
56 | is( $it->next->name, "foo", "iterator->next ok" ); |
57 | $it->next; |
58 | is( $it->next->name, "Artist 2", "iterator->next ok" ); |
59 | is( $it->next, undef, "next past end of resultset ok" ); |
60 | |
61 | my $test_type_info = { |
62 | 'artistid' => { |
63 | 'data_type' => 'INTEGER', |
64 | 'is_nullable' => 0, |
65 | 'size' => 10 |
66 | }, |
67 | 'name' => { |
68 | 'data_type' => 'VARCHAR', |
69 | 'is_nullable' => 1, |
70 | 'size' => 255 |
71 | }, |
a466dec9 |
72 | 'rank' => { |
73 | 'data_type' => 'INTEGER', |
74 | 'is_nullable' => 0, |
75 | 'size' => 10, |
76 | }, |
8e14d52c |
77 | 'charfield' => { |
78 | 'data_type' => 'CHAR', |
79 | 'is_nullable' => 1, |
8273e845 |
80 | 'size' => 10 |
8e14d52c |
81 | }, |
82 | }; |
83 | |
84 | |
3ff5b740 |
85 | my $type_info = $schema->storage->columns_info_for('artist'); |
8e14d52c |
86 | is_deeply($type_info, $test_type_info, 'columns_info_for - column data types'); |
87 | |
8e14d52c |
88 | # clean up our mess |
3ff5b740 |
89 | END { |
65d35121 |
90 | my $dbh = eval { $schema->storage->_dbh }; |
91 | $dbh->do("DROP TABLE artist") if $dbh; |
92 | undef $schema; |
3ff5b740 |
93 | } |