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