b6c43502cfd39a182c367aeba70cd1cf39e259c4
[dbsrgits/DBIx-Class.git] / t / 746db2_400.t
1 use DBIx::Class::Optional::Dependencies -skip_all_without => 'test_rdbms_db2_400';
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use DBIx::Class::Optional::Dependencies ();
8 use lib qw(t/lib);
9 use DBICTest;
10
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'
14 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_DB2_400_${_}" } qw/DSN USER PASS/};
15
16 plan tests => 6;
17
18 my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
19
20 my $dbh = $schema->storage->dbh;
21
22 eval { $dbh->do("DROP TABLE artist") };
23
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 )
31
32 # Just to test loading, already in Core
33 $schema->class('Artist')->load_components('PK::Auto');
34
35 # test primary key handling
36 my $new = $schema->resultset('Artist')->create({ name => 'foo' });
37 ok($new->artistid, "Auto-PK worked");
38
39 # test LIMIT support
40 for (1..6) {
41     $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
42 }
43 my $it = $schema->resultset('Artist')->search( {},
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     },
65     'rank' => {
66         'data_type' => 'INTEGER',
67         'is_nullable' => 0,
68         'size' => 10,
69     },
70     'charfield' => {
71         'data_type' => 'CHAR',
72         'is_nullable' => 1,
73         'size' => 10
74     },
75 };
76
77
78 my $type_info = $schema->storage->columns_info_for('artist');
79 is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
80
81 # clean up our mess
82 END {
83   my $dbh = eval { $schema->storage->_dbh };
84   $dbh->do("DROP TABLE artist") if $dbh;
85   undef $schema;
86 }