Get rid of Path::Class ( that *does* feel good )
[dbsrgits/DBIx-Class.git] / t / 746db2_400.t
1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2 use DBIx::Class::Optional::Dependencies -skip_all_without => 'test_rdbms_db2_400';
3
4 use strict;
5 use warnings;
6
7 use Test::More;
8 use DBIx::Class::Optional::Dependencies ();
9
10 use DBICTest;
11
12 # Probably best to pass the DBQ option in the DSN to specify a specific
13 # libray.  Something like:
14 # DBICTEST_DB2_400_DSN='dbi:ODBC:dsn=MyAS400;DBQ=MYLIB'
15 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_DB2_400_${_}" } qw/DSN USER PASS/};
16
17 plan tests => 6;
18
19 my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
20
21 my $dbh = $schema->storage->dbh;
22
23 eval { $dbh->do("DROP TABLE artist") };
24
25 $dbh->do(<<'');
26 CREATE TABLE artist (
27     artistid INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
28     name VARCHAR(255),
29     rank INTEGER default 13 not null,
30     charfield CHAR(10)
31 )
32
33 # Just to test loading, already in Core
34 $schema->class('Artist')->load_components('PK::Auto');
35
36 # test primary key handling
37 my $new = $schema->resultset('Artist')->create({ name => 'foo' });
38 ok($new->artistid, "Auto-PK worked");
39
40 # test LIMIT support
41 for (1..6) {
42     $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
43 }
44 my $it = $schema->resultset('Artist')->search( {},
45     { rows => 3,
46       order_by => 'artistid'
47       }
48 );
49 is( $it->count, 3, "LIMIT count ok" );
50 is( $it->next->name, "foo", "iterator->next ok" );
51 $it->next;
52 is( $it->next->name, "Artist 2", "iterator->next ok" );
53 is( $it->next, undef, "next past end of resultset ok" );
54
55 my $test_type_info = {
56     'artistid' => {
57         'data_type' => 'INTEGER',
58         'is_nullable' => 0,
59         'size' => 10
60     },
61     'name' => {
62         'data_type' => 'VARCHAR',
63         'is_nullable' => 1,
64         'size' => 255
65     },
66     'rank' => {
67         'data_type' => 'INTEGER',
68         'is_nullable' => 0,
69         'size' => 10,
70     },
71     'charfield' => {
72         'data_type' => 'CHAR',
73         'is_nullable' => 1,
74         'size' => 10
75     },
76 };
77
78
79 my $type_info = $schema->storage->columns_info_for('artist');
80 is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
81
82 # clean up our mess
83 END {
84   my $dbh = eval { $schema->storage->_dbh };
85   $dbh->do("DROP TABLE artist") if $dbh;
86   undef $schema;
87 }