Factor SQL-standard deferred FK checks into a component
[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
2c2bc4e5 24require DBICTest::Schema;
3ff5b740 25my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
8e14d52c 26
3ff5b740 27my $dbh = $schema->storage->dbh;
8e14d52c 28
c1cac633 29eval { $dbh->do("DROP TABLE artist") };
8e14d52c 30
a466dec9 31$dbh->do(<<'');
32CREATE TABLE artist (
33 artistid INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
34 name VARCHAR(255),
35 rank INTEGER default 13 not null,
36 charfield CHAR(10)
37)
8e14d52c 38
3ff5b740 39# Just to test loading, already in Core
40$schema->class('Artist')->load_components('PK::Auto');
8e14d52c 41
42# test primary key handling
3ff5b740 43my $new = $schema->resultset('Artist')->create({ name => 'foo' });
8e14d52c 44ok($new->artistid, "Auto-PK worked");
45
46# test LIMIT support
47for (1..6) {
3ff5b740 48 $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
8e14d52c 49}
3ff5b740 50my $it = $schema->resultset('Artist')->search( {},
8e14d52c 51 { rows => 3,
52 order_by => 'artistid'
53 }
54);
55is( $it->count, 3, "LIMIT count ok" );
56is( $it->next->name, "foo", "iterator->next ok" );
57$it->next;
58is( $it->next->name, "Artist 2", "iterator->next ok" );
59is( $it->next, undef, "next past end of resultset ok" );
60
61my $test_type_info = {
62 'artistid' => {
63 'data_type' => 'INTEGER',
64 'is_nullable' => 0,
65 'size' => 10
66 },
67 'name' => {
68 'data_type' => 'VARCHAR',
69 'is_nullable' => 1,
70 'size' => 255
71 },
a466dec9 72 'rank' => {
73 'data_type' => 'INTEGER',
74 'is_nullable' => 0,
75 'size' => 10,
76 },
8e14d52c 77 'charfield' => {
78 'data_type' => 'CHAR',
79 'is_nullable' => 1,
8273e845 80 'size' => 10
8e14d52c 81 },
82};
83
84
3ff5b740 85my $type_info = $schema->storage->columns_info_for('artist');
8e14d52c 86is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
87
8e14d52c 88# clean up our mess
3ff5b740 89END {
65d35121 90 my $dbh = eval { $schema->storage->_dbh };
91 $dbh->do("DROP TABLE artist") if $dbh;
92 undef $schema;
3ff5b740 93}