9 package DBICTest::Schema::Casecheck;
13 use base 'DBIx::Class';
15 __PACKAGE__->load_components(qw/Core/);
16 __PACKAGE__->table('casecheck');
17 __PACKAGE__->add_columns(qw/id name NAME uc_name/);
18 __PACKAGE__->column_info_from_storage(1);
19 __PACKAGE__->set_primary_key('id');
23 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/};
25 #warn "$dsn $user $pass";
27 plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test'
28 . ' (note: creates and drops tables named artist and casecheck!)' unless ($dsn && $user);
32 DBICTest::Schema->load_classes( 'Casecheck' );
33 my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
35 my $dbh = $schema->storage->dbh;
36 $schema->source("Artist")->name("testschema.artist");
37 $dbh->do("CREATE SCHEMA testschema;");
38 $dbh->do("CREATE TABLE testschema.artist (artistid serial PRIMARY KEY, name VARCHAR(100), charfield CHAR(10));");
39 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');
41 # This is in Core now, but it's here just to test that it doesn't break
42 $schema->class('Artist')->load_components('PK::Auto');
44 my $new = $schema->resultset('Artist')->create({ name => 'foo' });
46 is($new->artistid, 1, "Auto-PK worked");
48 $new = $schema->resultset('Artist')->create({ name => 'bar' });
50 is($new->artistid, 2, "Auto-PK worked");
52 my $test_type_info = {
54 'data_type' => 'integer',
59 'data_type' => 'character varying',
62 'default_value' => undef,
65 'data_type' => 'character',
68 'default_value' => undef,
73 my $type_info = $schema->storage->columns_info_for('testschema.artist');
74 my $artistid_defval = delete $type_info->{artistid}->{default_value};
75 like($artistid_defval,
76 qr/^nextval\('([^\.]*\.){0,1}artist_artistid_seq'::(?:text|regclass)\)/,
77 'columns_info_for - sequence matches Pg get_autoinc_seq expectations');
78 is_deeply($type_info, $test_type_info,
79 'columns_info_for - column data types');
81 my $name_info = $schema->source('Casecheck')->column_info( 'name' );
82 is( $name_info->{size}, 1, "Case sensitive matching info for 'name'" );
84 my $NAME_info = $schema->source('Casecheck')->column_info( 'NAME' );
85 is( $NAME_info->{size}, 2, "Case sensitive matching info for 'NAME'" );
87 my $uc_name_info = $schema->source('Casecheck')->column_info( 'uc_name' );
88 is( $uc_name_info->{size}, 3, "Case insensitive matching info for 'uc_name'" );
92 $dbh->do("DROP TABLE testschema.artist;");
93 $dbh->do("DROP TABLE testschema.casecheck;");
94 $dbh->do("DROP SCHEMA testschema;");