Patch for ? in NoBindVars data from Tom Hukins
[dbsrgits/DBIx-Class-Historic.git] / t / 72pg.t
CommitLineData
70350518 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
7
89add887 8{
9 package DBICTest::Schema::Casecheck;
10
11 use strict;
12 use warnings;
13 use base 'DBIx::Class';
14
3ff5b740 15 __PACKAGE__->load_components(qw/Core/);
89add887 16 __PACKAGE__->table('casecheck');
17 __PACKAGE__->add_columns(qw/id name NAME uc_name/);
d9916234 18 __PACKAGE__->column_info_from_storage(1);
89add887 19 __PACKAGE__->set_primary_key('id');
20
21}
22
0567538f 23my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/};
24
25#warn "$dsn $user $pass";
26
70350518 27plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test'
ae515736 28 . ' (note: creates and drops tables named artist and casecheck!)' unless ($dsn && $user);
0567538f 29
ae515736 30plan tests => 8;
0567538f 31
89add887 32DBICTest::Schema->load_classes( 'Casecheck' );
3ff5b740 33my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
0567538f 34
3ff5b740 35my $dbh = $schema->storage->dbh;
36$schema->source("Artist")->name("testschema.artist");
4d272ce5 37$dbh->do("CREATE SCHEMA testschema;");
ae515736 38$dbh->do("CREATE TABLE testschema.artist (artistid serial PRIMARY KEY, name VARCHAR(100), charfield CHAR(10));");
39ok ( $dbh->do('CREATE TABLE testschema.casecheck (id serial PRIMARY KEY, "name" VARCHAR(1), "NAME" VARCHAR(2), "UC_NAME" VARCHAR(3));'), 'Creation of casecheck table');
0567538f 40
3ff5b740 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');
0567538f 43
3ff5b740 44my $new = $schema->resultset('Artist')->create({ name => 'foo' });
0567538f 45
b6b65a3e 46is($new->artistid, 1, "Auto-PK worked");
47
3ff5b740 48$new = $schema->resultset('Artist')->create({ name => 'bar' });
b6b65a3e 49
50is($new->artistid, 2, "Auto-PK worked");
51
a953d8d9 52my $test_type_info = {
53 'artistid' => {
103e3e03 54 'data_type' => 'integer',
55 'is_nullable' => 0,
fc22fbac 56 'size' => 4,
a953d8d9 57 },
58 'name' => {
103e3e03 59 'data_type' => 'character varying',
60 'is_nullable' => 1,
ae515736 61 'size' => 100,
fc22fbac 62 'default_value' => undef,
103e3e03 63 },
64 'charfield' => {
65 'data_type' => 'character',
a953d8d9 66 'is_nullable' => 1,
fc22fbac 67 'size' => 10,
68 'default_value' => undef,
103e3e03 69 },
a953d8d9 70};
71
fc22fbac 72
3ff5b740 73my $type_info = $schema->storage->columns_info_for('testschema.artist');
fc22fbac 74my $artistid_defval = delete $type_info->{artistid}->{default_value};
75like($artistid_defval,
4d272ce5 76 qr/^nextval\('([^\.]*\.){0,1}artist_artistid_seq'::(?:text|regclass)\)/,
fc22fbac 77 'columns_info_for - sequence matches Pg get_autoinc_seq expectations');
78is_deeply($type_info, $test_type_info,
79 'columns_info_for - column data types');
a953d8d9 80
3ff5b740 81my $name_info = $schema->source('Casecheck')->column_info( 'name' );
ae515736 82is( $name_info->{size}, 1, "Case sensitive matching info for 'name'" );
83
3ff5b740 84my $NAME_info = $schema->source('Casecheck')->column_info( 'NAME' );
ae515736 85is( $NAME_info->{size}, 2, "Case sensitive matching info for 'NAME'" );
86
3ff5b740 87my $uc_name_info = $schema->source('Casecheck')->column_info( 'uc_name' );
ae515736 88is( $uc_name_info->{size}, 3, "Case insensitive matching info for 'uc_name'" );
89
3ff5b740 90END {
91 if($dbh) {
92 $dbh->do("DROP TABLE testschema.artist;");
93 $dbh->do("DROP TABLE testschema.casecheck;");
94 $dbh->do("DROP SCHEMA testschema;");
95 }
96}
0567538f 97