Skip Menu |

This queue is for tickets about the Class-DBI-Pg CPAN distribution.

Report information
The Basics
Id: 7097
Status: resolved
Priority: 0/
Queue: Class-DBI-Pg

People
Owner: Nobody in particular
Requestors: perl [...] simonflack.com
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 0.03
Fixed in: (no value)



Subject: CDBI::Pg doesn't find compound primary keys
create table foo ( bar numeric (10) not null, baz numeric (10) not null, qux varchar (255), constraint pk_foo primary key (bar,baz( ); on a table that has a compound primary key, I get this error: "foo has no primary key" I've attached a patch to Class::DBI::Pg 0.03 to support tables with compound primary keys
--- Class-DBI-Pg.pm.orig Sun Jul 25 21:29:03 2004 +++ Class-DBI-Pg.pm Sun Jul 25 21:40:58 2004 @@ -24,5 +24,5 @@ SQL $sth->execute($table); - my $prinum = $sth->fetchrow_array; + my %prinum = map { $_ => 1 } split '', $sth->fetchrow_array; $sth->finish; @@ -51,15 +51,15 @@ my($sequence) = $nextval_str =~ m/^nextval\('"?([^"']+)"?'::text\)/; - my(@cols, $primary); + my(@cols, @primary); foreach my $col(@$columns) { # skip dropped column. next if $col->[0] =~ /^\.+pg\.dropped\.\d+\.+$/; push @cols, $col->[0]; - next unless $prinum && $col->[1] eq $prinum; - $primary = $col->[0]; + next unless $prinum{$col->[1]}; + push @primary, $col->[0]; } - _croak("$table has no primary key") unless $primary; + _croak("$table has no primary key") unless @primary; $class->table($table); - $class->columns(Primary => $primary); + $class->columns(Primary => @primary); $class->columns(All => @cols); $class->sequence($sequence) if $sequence;
The diff was missing an important whitespace. Fixed version is attached
Download CDBI-Pg-multi_pri_keys.diff-FIXED
application/octet-stream 1013b

Message body not shown because it is not plain text.