9 package DBICTest::Schema::Casecheck;
13 use base 'DBIx::Class';
15 __PACKAGE__->load_components(qw/PK::Auto Core/);
16 __PACKAGE__->table('casecheck');
17 __PACKAGE__->add_columns(qw/id name NAME uc_name/);
18 __PACKAGE__->set_primary_key('id');
22 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/};
24 #warn "$dsn $user $pass";
26 plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test'
27 . ' (note: creates and drops tables named artist and casecheck!)' unless ($dsn && $user);
31 DBICTest::Schema->load_classes( 'Casecheck' );
32 DBICTest::Schema->compose_connection('PgTest' => $dsn, $user, $pass);
34 my $dbh = PgTest->schema->storage->dbh;
35 PgTest->schema->source("Artist")->name("testschema.artist");
36 $dbh->do("CREATE SCHEMA testschema;");
37 $dbh->do("CREATE TABLE testschema.artist (artistid serial PRIMARY KEY, name VARCHAR(100), charfield CHAR(10));");
38 ok ( $dbh->do('CREATE TABLE testschema.casecheck (id serial PRIMARY KEY, "name" VARCHAR(1), "NAME" VARCHAR(2), "UC_NAME" VARCHAR(3));'), 'Creation of casecheck table');
40 PgTest::Artist->load_components('PK::Auto');
42 my $new = PgTest::Artist->create({ name => 'foo' });
44 is($new->artistid, 1, "Auto-PK worked");
46 $new = PgTest::Artist->create({ name => 'bar' });
48 is($new->artistid, 2, "Auto-PK worked");
50 my $test_type_info = {
52 'data_type' => 'integer',
57 'data_type' => 'character varying',
60 'default_value' => undef,
63 'data_type' => 'character',
66 'default_value' => undef,
71 my $type_info = PgTest->schema->storage->columns_info_for('testschema.artist');
72 my $artistid_defval = delete $type_info->{artistid}->{default_value};
73 like($artistid_defval,
74 qr/^nextval\('([^\.]*\.){0,1}artist_artistid_seq'::(?:text|regclass)\)/,
75 'columns_info_for - sequence matches Pg get_autoinc_seq expectations');
76 is_deeply($type_info, $test_type_info,
77 'columns_info_for - column data types');
79 my $name_info = PgTest::Casecheck->column_info( 'name' );
80 is( $name_info->{size}, 1, "Case sensitive matching info for 'name'" );
82 my $NAME_info = PgTest::Casecheck->column_info( 'NAME' );
83 is( $NAME_info->{size}, 2, "Case sensitive matching info for 'NAME'" );
85 my $uc_name_info = PgTest::Casecheck->column_info( 'uc_name' );
86 is( $uc_name_info->{size}, 3, "Case insensitive matching info for 'uc_name'" );
88 $dbh->do("DROP TABLE testschema.artist;");
89 $dbh->do("DROP TABLE testschema.casecheck;");
90 $dbh->do("DROP SCHEMA testschema;");