Introduce GOVERNANCE document and empty RESOLUTIONS file.
[dbsrgits/DBIx-Class.git] / t / 746db2_400.t
CommitLineData
c0329273 1BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
cb551b07 2use DBIx::Class::Optional::Dependencies -skip_all_without => 'test_rdbms_db2_400';
3
70350518 4use strict;
68de9438 5use warnings;
70350518 6
7use Test::More;
c0329273 8
70350518 9use DBICTest;
8e14d52c 10
8e14d52c 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'
cb551b07 14my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_DB2_400_${_}" } qw/DSN USER PASS/};
8e14d52c 15
16plan tests => 6;
17
3ff5b740 18my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
8e14d52c 19
3ff5b740 20my $dbh = $schema->storage->dbh;
8e14d52c 21
c1cac633 22eval { $dbh->do("DROP TABLE artist") };
8e14d52c 23
a466dec9 24$dbh->do(<<'');
25CREATE 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)
8e14d52c 31
3ff5b740 32# Just to test loading, already in Core
33$schema->class('Artist')->load_components('PK::Auto');
8e14d52c 34
35# test primary key handling
3ff5b740 36my $new = $schema->resultset('Artist')->create({ name => 'foo' });
8e14d52c 37ok($new->artistid, "Auto-PK worked");
38
39# test LIMIT support
40for (1..6) {
3ff5b740 41 $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
8e14d52c 42}
3ff5b740 43my $it = $schema->resultset('Artist')->search( {},
8e14d52c 44 { rows => 3,
45 order_by => 'artistid'
46 }
47);
48is( $it->count, 3, "LIMIT count ok" );
49is( $it->next->name, "foo", "iterator->next ok" );
50$it->next;
51is( $it->next->name, "Artist 2", "iterator->next ok" );
52is( $it->next, undef, "next past end of resultset ok" );
53
54my $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 },
a466dec9 65 'rank' => {
66 'data_type' => 'INTEGER',
67 'is_nullable' => 0,
68 'size' => 10,
69 },
8e14d52c 70 'charfield' => {
71 'data_type' => 'CHAR',
72 'is_nullable' => 1,
8273e845 73 'size' => 10
8e14d52c 74 },
75};
76
77
3ff5b740 78my $type_info = $schema->storage->columns_info_for('artist');
8e14d52c 79is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
80
8e14d52c 81# clean up our mess
3ff5b740 82END {
65d35121 83 my $dbh = eval { $schema->storage->_dbh };
84 $dbh->do("DROP TABLE artist") if $dbh;
85 undef $schema;
3ff5b740 86}