Commit | Line | Data |
70350518 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use lib qw(t/lib); |
6 | use DBICTest; |
843f8ecd |
7 | |
8 | my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_DB2_${_}" } qw/DSN USER PASS/}; |
9 | |
10 | #warn "$dsn $user $pass"; |
11 | |
58d387fe |
12 | plan skip_all => 'Set $ENV{DBICTEST_DB2_DSN}, _USER and _PASS to run this test' |
843f8ecd |
13 | unless ($dsn && $user); |
14 | |
25aa8311 |
15 | plan tests => 9; |
843f8ecd |
16 | |
3ff5b740 |
17 | my $schema = DBICTest::Schema->connect($dsn, $user, $pass); |
843f8ecd |
18 | |
3ff5b740 |
19 | my $dbh = $schema->storage->dbh; |
843f8ecd |
20 | |
88c00130 |
21 | eval { $dbh->do("DROP TABLE artist") }; |
843f8ecd |
22 | |
4e88dfc4 |
23 | $dbh->do("CREATE TABLE artist (artistid INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), name VARCHAR(255), charfield CHAR(10), rank INTEGER DEFAULT 13);"); |
843f8ecd |
24 | |
3ff5b740 |
25 | # This is in core, just testing that it still loads ok |
26 | $schema->class('Artist')->load_components('PK::Auto'); |
843f8ecd |
27 | |
25aa8311 |
28 | my $ars = $schema->resultset('Artist'); |
29 | |
843f8ecd |
30 | # test primary key handling |
25aa8311 |
31 | my $new = $ars->create({ name => 'foo' }); |
843f8ecd |
32 | ok($new->artistid, "Auto-PK worked"); |
33 | |
25aa8311 |
34 | my $init_count = $ars->count; |
843f8ecd |
35 | for (1..6) { |
25aa8311 |
36 | $ars->create({ name => 'Artist ' . $_ }); |
843f8ecd |
37 | } |
25aa8311 |
38 | is ($ars->count, $init_count + 6, 'Simple count works'); |
39 | |
40 | # test LIMIT support |
41 | my $it = $ars->search( {}, |
42 | { |
43 | rows => 3, |
44 | order_by => 'artistid' |
45 | } |
843f8ecd |
46 | ); |
47 | is( $it->count, 3, "LIMIT count ok" ); |
25aa8311 |
48 | |
49 | my @all = $it->all; |
50 | is (@all, 3, 'Number of ->all objects matches count'); |
51 | |
f2469db1 |
52 | $it->reset; |
fc22fbac |
53 | is( $it->next->name, "foo", "iterator->next ok" ); |
25aa8311 |
54 | is( $it->next->name, "Artist 1", "iterator->next ok" ); |
fc22fbac |
55 | is( $it->next->name, "Artist 2", "iterator->next ok" ); |
25aa8311 |
56 | is( $it->next, undef, "next past end of resultset ok" ); # this can not succeed if @all > 3 |
57 | |
843f8ecd |
58 | |
59 | my $test_type_info = { |
60 | 'artistid' => { |
61 | 'data_type' => 'INTEGER', |
62 | 'is_nullable' => 0, |
fc22fbac |
63 | 'size' => 10 |
843f8ecd |
64 | }, |
65 | 'name' => { |
66 | 'data_type' => 'VARCHAR', |
67 | 'is_nullable' => 1, |
68 | 'size' => 255 |
69 | }, |
70 | 'charfield' => { |
fc22fbac |
71 | 'data_type' => 'CHAR', |
843f8ecd |
72 | 'is_nullable' => 1, |
73 | 'size' => 10 |
74 | }, |
70c29d32 |
75 | 'rank' => { |
76 | 'data_type' => 'INTEGER', |
77 | 'is_nullable' => 1, |
78 | 'size' => 10 |
79 | }, |
843f8ecd |
80 | }; |
81 | |
82 | |
3ff5b740 |
83 | my $type_info = $schema->storage->columns_info_for('artist'); |
843f8ecd |
84 | is_deeply($type_info, $test_type_info, 'columns_info_for - column data types'); |
85 | |
843f8ecd |
86 | # clean up our mess |
3ff5b740 |
87 | END { |
88 | $dbh->do("DROP TABLE artist") if $dbh; |
89 | } |