Merge 'replication_dedux' into 'trunk'
[dbsrgits/DBIx-Class.git] / t / 746db2_400.t
CommitLineData
70350518 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
8e14d52c 7
8my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_DB2_400_${_}" } qw/DSN USER PASS/};
9
10#warn "$dsn $user $pass";
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'
58d387fe 15plan skip_all => 'Set $ENV{DBICTEST_DB2_400_DSN}, _USER and _PASS to run this test'
8e14d52c 16 unless ($dsn && $user);
17
18plan tests => 6;
19
3ff5b740 20my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
8e14d52c 21
3ff5b740 22my $dbh = $schema->storage->dbh;
8e14d52c 23
c1cac633 24eval { $dbh->do("DROP TABLE artist") };
8e14d52c 25
26$dbh->do("CREATE TABLE artist (artistid INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), name VARCHAR(255), charfield CHAR(10))");
27
3ff5b740 28# Just to test loading, already in Core
29$schema->class('Artist')->load_components('PK::Auto');
8e14d52c 30
31# test primary key handling
3ff5b740 32my $new = $schema->resultset('Artist')->create({ name => 'foo' });
8e14d52c 33ok($new->artistid, "Auto-PK worked");
34
35# test LIMIT support
36for (1..6) {
3ff5b740 37 $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
8e14d52c 38}
3ff5b740 39my $it = $schema->resultset('Artist')->search( {},
8e14d52c 40 { rows => 3,
41 order_by => 'artistid'
42 }
43);
44is( $it->count, 3, "LIMIT count ok" );
45is( $it->next->name, "foo", "iterator->next ok" );
46$it->next;
47is( $it->next->name, "Artist 2", "iterator->next ok" );
48is( $it->next, undef, "next past end of resultset ok" );
49
50my $test_type_info = {
51 'artistid' => {
52 'data_type' => 'INTEGER',
53 'is_nullable' => 0,
54 'size' => 10
55 },
56 'name' => {
57 'data_type' => 'VARCHAR',
58 'is_nullable' => 1,
59 'size' => 255
60 },
61 'charfield' => {
62 'data_type' => 'CHAR',
63 'is_nullable' => 1,
64 'size' => 10
65 },
66};
67
68
3ff5b740 69my $type_info = $schema->storage->columns_info_for('artist');
8e14d52c 70is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
71
8e14d52c 72# clean up our mess
3ff5b740 73END {
74 $dbh->do("DROP TABLE artist") if $dbh;
75}
8e14d52c 76