use store_column instead of set_column on insert
[dbsrgits/DBIx-Class-Historic.git] / t / 745db2.t
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
58d387fe 12plan skip_all => 'Set $ENV{DBICTEST_DB2_DSN}, _USER and _PASS to run this test'
843f8ecd 13 unless ($dsn && $user);
14
fc22fbac 15plan tests => 6;
843f8ecd 16
3ff5b740 17my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
843f8ecd 18
3ff5b740 19my $dbh = $schema->storage->dbh;
843f8ecd 20
88c00130 21eval { $dbh->do("DROP TABLE artist") };
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
3ff5b740 25# This is in core, just testing that it still loads ok
26$schema->class('Artist')->load_components('PK::Auto');
843f8ecd 27
28# test primary key handling
3ff5b740 29my $new = $schema->resultset('Artist')->create({ name => 'foo' });
843f8ecd 30ok($new->artistid, "Auto-PK worked");
31
32# test LIMIT support
33for (1..6) {
3ff5b740 34 $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
843f8ecd 35}
3ff5b740 36my $it = $schema->resultset('Artist')->search( {},
843f8ecd 37 { rows => 3,
38 order_by => 'artistid'
39 }
40);
41is( $it->count, 3, "LIMIT count ok" );
fc22fbac 42is( $it->next->name, "foo", "iterator->next ok" );
843f8ecd 43$it->next;
fc22fbac 44is( $it->next->name, "Artist 2", "iterator->next ok" );
843f8ecd 45is( $it->next, undef, "next past end of resultset ok" );
46
47my $test_type_info = {
48 'artistid' => {
49 'data_type' => 'INTEGER',
50 'is_nullable' => 0,
fc22fbac 51 'size' => 10
843f8ecd 52 },
53 'name' => {
54 'data_type' => 'VARCHAR',
55 'is_nullable' => 1,
56 'size' => 255
57 },
58 'charfield' => {
fc22fbac 59 'data_type' => 'CHAR',
843f8ecd 60 'is_nullable' => 1,
61 'size' => 10
62 },
63};
64
65
3ff5b740 66my $type_info = $schema->storage->columns_info_for('artist');
843f8ecd 67is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
68
843f8ecd 69# clean up our mess
3ff5b740 70END {
71 $dbh->do("DROP TABLE artist") if $dbh;
72}