Merge 'reorganize_tests' into 'DBIx-Class-current'
[dbsrgits/DBIx-Class.git] / t / run / 145db2.tl
CommitLineData
70350518 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
843f8ecd 7
8my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_DB2_${_}" } qw/DSN USER PASS/};
9
10#warn "$dsn $user $pass";
11
12plan skip_all, 'Set $ENV{DBICTEST_DB2_DSN}, _USER and _PASS to run this test'
13 unless ($dsn && $user);
14
fc22fbac 15plan tests => 6;
843f8ecd 16
17DBICTest::Schema->compose_connection('DB2Test' => $dsn, $user, $pass);
18
19my $dbh = DB2Test->schema->storage->dbh;
20
be194671 21$dbh->do("DROP TABLE artist", { RaiseError => 0, PrintError => 0 });
843f8ecd 22
23$dbh->do("CREATE TABLE artist (artistid INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), name VARCHAR(255), charfield CHAR(10));");
24
25#'dbi:mysql:host=localhost;database=dbic_test', 'dbic_test', '');
26
27DB2Test::Artist->load_components('PK::Auto');
28
29# test primary key handling
30my $new = DB2Test::Artist->create({ name => 'foo' });
31ok($new->artistid, "Auto-PK worked");
32
33# test LIMIT support
34for (1..6) {
35 DB2Test::Artist->create({ name => 'Artist ' . $_ });
36}
37my $it = DB2Test::Artist->search( {},
38 { rows => 3,
39 order_by => 'artistid'
40 }
41);
42is( $it->count, 3, "LIMIT count ok" );
fc22fbac 43is( $it->next->name, "foo", "iterator->next ok" );
843f8ecd 44$it->next;
fc22fbac 45is( $it->next->name, "Artist 2", "iterator->next ok" );
843f8ecd 46is( $it->next, undef, "next past end of resultset ok" );
47
48my $test_type_info = {
49 'artistid' => {
50 'data_type' => 'INTEGER',
51 'is_nullable' => 0,
fc22fbac 52 'size' => 10
843f8ecd 53 },
54 'name' => {
55 'data_type' => 'VARCHAR',
56 'is_nullable' => 1,
57 'size' => 255
58 },
59 'charfield' => {
fc22fbac 60 'data_type' => 'CHAR',
843f8ecd 61 'is_nullable' => 1,
62 'size' => 10
63 },
64};
65
66
67my $type_info = DB2Test->schema->storage->columns_info_for('artist');
68is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
69
70
71
72# clean up our mess
73$dbh->do("DROP TABLE artist");
74