Restore ability to handle underdefined root (t/prefetch/incomplete.t)
[dbsrgits/DBIx-Class.git] / t / 746db2_400.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5 use DBIx::Class::Optional::Dependencies ();
6 use lib qw(t/lib);
7 use DBICTest;
8
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
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'
19 plan skip_all => 'Set $ENV{DBICTEST_DB2_400_DSN}, _USER and _PASS to run this test'
20   unless ($dsn && $user);
21
22 plan tests => 6;
23
24 my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
25
26 my $dbh = $schema->storage->dbh;
27
28 eval { $dbh->do("DROP TABLE artist") };
29
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 )
37
38 # Just to test loading, already in Core
39 $schema->class('Artist')->load_components('PK::Auto');
40
41 # test primary key handling
42 my $new = $schema->resultset('Artist')->create({ name => 'foo' });
43 ok($new->artistid, "Auto-PK worked");
44
45 # test LIMIT support
46 for (1..6) {
47     $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
48 }
49 my $it = $schema->resultset('Artist')->search( {},
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     },
71     'rank' => {
72         'data_type' => 'INTEGER',
73         'is_nullable' => 0,
74         'size' => 10,
75     },
76     'charfield' => {
77         'data_type' => 'CHAR',
78         'is_nullable' => 1,
79         'size' => 10
80     },
81 };
82
83
84 my $type_info = $schema->storage->columns_info_for('artist');
85 is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
86
87 # clean up our mess
88 END {
89   my $dbh = eval { $schema->storage->_dbh };
90   $dbh->do("DROP TABLE artist") if $dbh;
91   undef $schema;
92 }