Skip Menu |
 

This queue is for tickets about the SQL-Translator CPAN distribution.

Report information
The Basics
Id: 80553
Status: new
Priority: 0/
Queue: SQL-Translator

People
Owner: Nobody in particular
Requestors: JDS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.11016
Fixed in: (no value)



Subject: parse() in SQL::Translator::Parser::DBI::PostgreSQL does not handle multi-column primary keys
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
X-RT-Original-Encoding: utf-8
Content-Type: multipart/mixed; boundary="----------=_1351802360-12629-2"
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 0
Content-Type: text/plain; charset="UTF-8"
Content-Disposition: inline
Content-Transfer-Encoding: binary
Content-Length: 853
Download (untitled) / with headers
text/plain 853b
Setup: (1) PostgreSQL table having a primary key involving more than one column , see attachment Create_table.sql (2) Calling translate() on an SQL::Translator for a database containing the above table, see attachment test.pl. ---------------------------------------- Error message: Argument "1 2" isn't numeric in subtraction (-) at C:/strawberry/perl/site/lib/SQL/Translator/Parser/DBI/PostgreSQL.pm l ine 157. ---------------------------------------- Reason: In line 157, the parse() method tries to determine a column name for the current primary key: my $col_name=$column_names[($$indexhash{'indkey'} - 1)]; But in the test case, the primary key consists of two columns with indices 1 and 2. ---------------------------------------- Possible resolution: A proposal for a small patch can be found in the attachment PostgreSQL.patch.
Subject: test.pl
MIME-Version: 1.0
Content-Type: application/octet-stream; name="test.pl"
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline; filename="test.pl"
Content-Transfer-Encoding: base64
Content-Length: 280
Download test.pl
text/x-perl 280b
use strict; use warnings; use DBI; use SQL::Translator; my $dbh = DBI->connect( 'dbi:Pg:dbname=playground', 'postgres', '********' ); my $translator = SQL::Translator->new( parser => 'DBI', parser_args => { dbh => $dbh, } ); $translator->translate();
Subject: Create_table.sql
MIME-Version: 1.0
Content-Type: application/octet-stream; name="Create_table.sql"
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline; filename="Create_table.sql"
Content-Transfer-Encoding: base64
Content-Length: 175
Download Create_table.sql
application/octet-stream 175b

Message body not shown because it is not plain text.

Subject: PostgreSQL.patch
MIME-Version: 1.0
Content-Type: application/octet-stream; name="PostgreSQL.patch"
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline; filename="PostgreSQL.patch"
Content-Transfer-Encoding: base64
Content-Length: 1246
Download PostgreSQL.patch
text/x-diff 1.2k
--- C:/Users/jose/CPAN/SQL-Translator-Parser-DBI-PostgreSQL/PostgreSQL.pm Thu Nov 01 21:28:38 2012 +++ C:/Users/jose/CPAN/SQL-Translator-Parser-DBI-PostgreSQL/PostgreSQL_patched.pm Thu Nov 01 21:28:57 2012 @@ -150,12 +150,16 @@ or !defined($$indexhash{'indkey'}) ); my $type; + my @column_ids = split /\s+/, $$indexhash{'indkey'}; + if ($$indexhash{'indisprimary'}) { $type = UNIQUE; #PRIMARY_KEY; #tell sqlt that this is the primary key: - my $col_name=$column_names[($$indexhash{'indkey'} - 1)]; - $table->get_field($col_name)->{is_primary_key}=1; + foreach my $column_id (@column_ids) { + my $col_name=$column_names[($column_id - 1)]; + $table->get_field($col_name)->{is_primary_key}=1; + } } elsif ($$indexhash{'indisunique'}) { $type = UNIQUE; @@ -163,8 +167,7 @@ $type = NORMAL; } - - my @column_ids = split /\s+/, $$indexhash{'indkey'}; + my @columns = split /\s+/, $$indexhash{'attname'}; $table->add_index(


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.