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