Subject: | [PATCH] Fix ORDINAL_POSITION in foreign_key_info |
Date: | Thu, 19 Sep 2013 00:29:37 +0200 |
To: | bug-DBD-Pg [...] rt.cpan.org |
From: | ilmari [...] ilmari.org (Dagfinn Ilmari Mannsåker) |
It's supposed to be the column's position in the constraint,
not the position in the referring table.
--
- Twitter seems more influential [than blogs] in the 'gets reported in
the mainstream press' sense at least. - Matt McLeod
- That'd be because the content of a tweet is easier to condense down
to a mainstream media article. - Calle Dybedahl
From 24bf31241e7c3c1eace9f7474758b6b2d6488d01 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <ilmari@ilmari.org>
Date: Wed, 18 Sep 2013 23:25:34 +0100
Subject: [PATCH] Fix ORDINAL_POSITION in foreign_key_info
It's supposed to be the column's position in the constraint,
not the position in the referring table.
---
Pg.pm | 2 +-
t/03dbmethod.t | 10 +++++-----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/Pg.pm b/Pg.pm
index 4306a80..c620d21 100644
--- a/Pg.pm
+++ b/Pg.pm
@@ -1044,7 +1044,7 @@ use 5.006001;
# FK_COLUMN_NAME
$fkinfo->[$x][7] = $attinfo{$t->{'conrelid'}}{$conkey->[$y]}{'colname'};
# ORDINAL_POSITION
- $fkinfo->[$x][8] = $conkey->[$y];
+ $fkinfo->[$x][8] = $y+1;
# UPDATE_RULE
$fkinfo->[$x][9] = "$t->{'update'}";
# DELETE_RULE
diff --git a/t/03dbmethod.t b/t/03dbmethod.t
index 76286fe..c831175 100644
--- a/t/03dbmethod.t
+++ b/t/03dbmethod.t
@@ -902,7 +902,7 @@ my $fk1 = [
$schema2, ## FK Schema
$table2, ## FK Table
'f2', ## FK Table
- 2, ## Ordinal position
+ 1, ## Ordinal position
3, ## Update rule
3, ## Delete rule
'dbd_pg_test2_fk1', ## FK name
@@ -945,7 +945,7 @@ my $fk2 = [
$schema2,
$table2,
'f3',
- '3',
+ '1',
'0', ## cascade
'2', ## set null
'dbd_pg_test2_fk2',
@@ -976,7 +976,7 @@ my $fk3 = [
$schema2,
$table2,
'f3',
- '3',
+ '1',
'4', ## set default
'1', ## restrict
'dbd_pg_test2_aafk3',
@@ -1064,8 +1064,8 @@ my $fk5 = [
# primary column name [3]
# foreign column name [7]
# ordinal position [8]
-my @fk6 = @$fk5; my $fk6 = \@fk6; $fk6->[3] = 'a'; $fk6->[7] = 'f3'; $fk6->[8] = 3;
-my @fk7 = @$fk5; my $fk7 = \@fk7; $fk7->[3] = 'b'; $fk7->[7] = 'f2'; $fk7->[8] = 2;
+my @fk6 = @$fk5; my $fk6 = \@fk6; $fk6->[3] = 'a'; $fk6->[7] = 'f3'; $fk6->[8] = 2;
+my @fk7 = @$fk5; my $fk7 = \@fk7; $fk7->[3] = 'b'; $fk7->[7] = 'f2'; $fk7->[8] = 3;
$expected = [$fk3,$fk1,$fk2,$fk5,$fk6,$fk7];
is_deeply ($result, $expected, $t);
--
1.8.1.2