From: Robert Buels Date: Thu, 6 Aug 2009 19:42:30 +0000 (+0000) Subject: fix for pg non-schema-qualified thing, with a nice vague commit message. performance... X-Git-Tag: v0.08109~2^2~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7dfe289b0aa53b8a0e522545ae294d785aa9ed19;p=dbsrgits%2FDBIx-Class.git fix for pg non-schema-qualified thing, with a nice vague commit message. performance should be the same as before, for the common (schema-qualified) case --- diff --git a/lib/DBIx/Class/Storage/DBI/Pg.pm b/lib/DBIx/Class/Storage/DBI/Pg.pm index 3935a49..e925529 100644 --- a/lib/DBIx/Class/Storage/DBI/Pg.pm +++ b/lib/DBIx/Class/Storage/DBI/Pg.pm @@ -36,14 +36,40 @@ sub last_insert_id { sub _dbh_get_autoinc_seq { my ($self, $dbh, $schema, $table, @pri) = @_; - while (my $col = shift @pri) { - my $info = $dbh->column_info(undef,$schema,$table,$col)->fetchrow_hashref; - if(defined $info->{COLUMN_DEF} and - $info->{COLUMN_DEF} =~ /^nextval\(+'([^']+)'::(?:text|regclass)\)/) { - my $seq = $1; - # may need to strip quotes -- see if this works - return $seq =~ /\./ ? $seq : $info->{TABLE_SCHEM} . "." . $seq; - } + # get the list of postgres schemas to search. if we have a schema + # specified, use that. otherwise, use the search path + my @search_path; + if( defined $schema and length $schema ) { + @search_path = ( $schema ); + } else { + my ($search_path) = $dbh->selectrow_array('SHOW search_path'); + while( $search_path =~ s/([^,]+),?// ) { + unless( defined $1 and length $1 ) { + $self->throw_exception("search path sanity check failed: '$1'") + } + push @search_path, $1; + } + } + + foreach my $search_schema (@search_path) { + foreach my $col (@pri) { + my $info = $dbh->column_info(undef,$search_schema,$table,$col)->fetchrow_hashref; + if($info) { + # if we get here, we have definitely found the right + # column. + if( defined $info->{COLUMN_DEF} and + $info->{COLUMN_DEF} + =~ /^nextval\(+'([^']+)'::(?:text|regclass)\)/i + ) { + my $seq = $1; + return $seq =~ /\./ ? $seq : $info->{TABLE_SCHEM} . "." . $seq; + } else { + # we have found the column, but cannot figure out + # the nextval seq + return; + } + } + } } return; }