make sure we take fresh copies of connect_info, safer than letting people mod it...
[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
c216324a 20DBICTest::Schema->compose_namespace('DB2Test' => $dsn, $user, $pass);
8e14d52c 21
22my $dbh = DB2Test->schema->storage->dbh;
23
24$dbh->do("DROP TABLE artist", { RaiseError => 0, PrintError => 0 });
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
28DB2Test::Artist->load_components('PK::Auto');
29
30# test primary key handling
31my $new = DB2Test::Artist->create({ name => 'foo' });
32ok($new->artistid, "Auto-PK worked");
33
34# test LIMIT support
35for (1..6) {
36 DB2Test::Artist->create({ name => 'Artist ' . $_ });
37}
38my $it = DB2Test::Artist->search( {},
39 { rows => 3,
40 order_by => 'artistid'
41 }
42);
43is( $it->count, 3, "LIMIT count ok" );
44is( $it->next->name, "foo", "iterator->next ok" );
45$it->next;
46is( $it->next->name, "Artist 2", "iterator->next ok" );
47is( $it->next, undef, "next past end of resultset ok" );
48
49my $test_type_info = {
50 'artistid' => {
51 'data_type' => 'INTEGER',
52 'is_nullable' => 0,
53 'size' => 10
54 },
55 'name' => {
56 'data_type' => 'VARCHAR',
57 'is_nullable' => 1,
58 'size' => 255
59 },
60 'charfield' => {
61 'data_type' => 'CHAR',
62 'is_nullable' => 1,
63 'size' => 10
64 },
65};
66
67
68my $type_info = DB2Test->schema->storage->columns_info_for('artist');
69is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
70
71
72
73# clean up our mess
74$dbh->do("DROP TABLE artist");
75