From: Jesper Krogh Date: Fri, 5 May 2006 17:25:54 +0000 (+0000) Subject: Fix to make the Postgresql-code handle Schemas. This should be non-intrusive to non... X-Git-Tag: v0.07002~75^2~210 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4d272ce5ce62edfd0e26fb499c585da9db3e4e4a;p=dbsrgits%2FDBIx-Class.git Fix to make the Postgresql-code handle Schemas. This should be non-intrusive to non-schema-users. --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 62cb900..196fdc9 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -666,7 +666,8 @@ sub columns_info_for { $dbh->{RaiseError} = 1; $dbh->{PrintError} = 0; eval { - my $sth = $dbh->column_info( undef, undef, $table, '%' ); + my ($schema,$tab) = $table =~ /^(.+?)\.(.+)$/ ? ($1,$2) : (undef,$table); + my $sth = $dbh->column_info( undef,$schema, $tab, '%' ); $sth->execute(); while ( my $info = $sth->fetchrow_hashref() ){ my %column_info; diff --git a/lib/DBIx/Class/Storage/DBI/Pg.pm b/lib/DBIx/Class/Storage/DBI/Pg.pm index 1352c25..526abac 100644 --- a/lib/DBIx/Class/Storage/DBI/Pg.pm +++ b/lib/DBIx/Class/Storage/DBI/Pg.pm @@ -21,11 +21,12 @@ sub get_autoinc_seq { my ($schema,$table) = $source->name =~ /^(.+)\.(.+)$/ ? ($1,$2) : (undef,$source->name); while (my $col = shift @pri) { - my $info = $dbh->column_info(undef,$schema,$table,$col)->fetchrow_arrayref; - if (defined $info->[12] and $info->[12] =~ + my $info = $dbh->column_info(undef,$schema,$table,$col)->fetchrow_hashref; + if (defined $info->{COLUMN_DEF} and $info->{COLUMN_DEF} =~ /^nextval\(+'([^']+)'::(?:text|regclass)\)/) { - return $1; # may need to strip quotes -- see if this works + my $seq = $1; + return $seq =~ /\./ ? $seq : $info->{TABLE_SCHEM} . "." . $seq; # may need to strip quotes -- see if this works } } } diff --git a/t/run/12pg.tl b/t/run/12pg.tl index ee3e819..d71e39c 100644 --- a/t/run/12pg.tl +++ b/t/run/12pg.tl @@ -1,6 +1,5 @@ sub run_tests { my $schema = shift; - my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/}; #warn "$dsn $user $pass"; @@ -13,8 +12,9 @@ plan tests => 4; DBICTest::Schema->compose_connection('PgTest' => $dsn, $user, $pass); my $dbh = PgTest->schema->storage->dbh; - -$dbh->do("CREATE TABLE artist (artistid serial PRIMARY KEY, name VARCHAR(255), charfield CHAR(10));"); +PgTest->schema->source("Artist")->name("testschema.artist"); +$dbh->do("CREATE SCHEMA testschema;"); +$dbh->do("CREATE TABLE testschema.artist (artistid serial PRIMARY KEY, name VARCHAR(255), charfield CHAR(10));"); PgTest::Artist->load_components('PK::Auto'); @@ -47,15 +47,16 @@ my $test_type_info = { }; -my $type_info = PgTest->schema->storage->columns_info_for('artist'); +my $type_info = PgTest->schema->storage->columns_info_for('testschema.artist'); my $artistid_defval = delete $type_info->{artistid}->{default_value}; like($artistid_defval, - qr/^nextval\('public\.artist_artistid_seq'::(?:text|regclass)\)/, + qr/^nextval\('([^\.]*\.){0,1}artist_artistid_seq'::(?:text|regclass)\)/, 'columns_info_for - sequence matches Pg get_autoinc_seq expectations'); is_deeply($type_info, $test_type_info, 'columns_info_for - column data types'); -$dbh->do("DROP TABLE artist;"); +$dbh->do("DROP TABLE testschema.artist;"); +$dbh->do("DROP SCHEMA testschema;"); }