Merge 'trunk' into 'replication_dedux'
[dbsrgits/DBIx-Class.git] / t / 745db2.t
1 use strict;
2 use warnings;  
3
4 use Test::More;
5 use lib qw(t/lib);
6 use DBICTest;
7
8 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_DB2_${_}" } qw/DSN USER PASS/};
9
10 #warn "$dsn $user $pass";
11
12 plan skip_all => 'Set $ENV{DBICTEST_DB2_DSN}, _USER and _PASS to run this test'
13   unless ($dsn && $user);
14
15 plan tests => 6;
16
17 my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
18
19 my $dbh = $schema->storage->dbh;
20
21 eval { $dbh->do("DROP TABLE artist") };
22
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));");
24
25 # This is in core, just testing that it still loads ok
26 $schema->class('Artist')->load_components('PK::Auto');
27
28 # test primary key handling
29 my $new = $schema->resultset('Artist')->create({ name => 'foo' });
30 ok($new->artistid, "Auto-PK worked");
31
32 # test LIMIT support
33 for (1..6) {
34     $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
35 }
36 my $it = $schema->resultset('Artist')->search( {},
37     { rows => 3,
38       order_by => 'artistid'
39       }
40 );
41 is( $it->count, 3, "LIMIT count ok" );
42 is( $it->next->name, "foo", "iterator->next ok" );
43 $it->next;
44 is( $it->next->name, "Artist 2", "iterator->next ok" );
45 is( $it->next, undef, "next past end of resultset ok" );
46
47 my $test_type_info = {
48     'artistid' => {
49         'data_type' => 'INTEGER',
50         'is_nullable' => 0,
51         'size' => 10
52     },
53     'name' => {
54         'data_type' => 'VARCHAR',
55         'is_nullable' => 1,
56         'size' => 255
57     },
58     'charfield' => {
59         'data_type' => 'CHAR',
60         'is_nullable' => 1,
61         'size' => 10 
62     },
63 };
64
65
66 my $type_info = $schema->storage->columns_info_for('artist');
67 is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
68
69 # clean up our mess
70 END {
71     $dbh->do("DROP TABLE artist") if $dbh;
72 }