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