Skip Menu |

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

Report information
The Basics
Id: 85836
Status: resolved
Priority: 0/
Queue: DBD-Pg

People
Owner: greg [...] turnstep.com
Requestors: mallah [...] tradeindia.com
Cc:
AdminCc:

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



Subject: primary_key_info fails on 32bit system for tables where oid is > max value of signed 32bit int
Date: Mon, 3 Jun 2013 23:17:27 +0530 (IST)
To: bug-DBD-Pg [...] rt.cpan.org
From: Rajesh Kumar Mallah <mallah [...] tradeindia.com>
Dear Admin, in function primary_key_info of DBD/Pg.pm the result of below select is stored in a perl integer . In case the value in c.oid > 2147483647 then info is truncated to that value only. hence the subsequent sql that is based on oid fails to get any result. 724 my $pri_key_sql = qq{ 725 SELECT 726 c.oid 727 , quote_ident(n.nspname) 728 , quote_ident(c.relname) 729 , quote_ident(c2.relname) 730 , i.indkey, quote_ident(t.spcname), quote_ident(t.spclocation) 731 , n.nspname, c.relname, c2.relname 732 FROM 733 pg_catalog.pg_class c 734 JOIN pg_catalog.pg_index i ON (i.indrelid = c.oid) 735 JOIN pg_catalog.pg_class c2 ON (c2.oid = i.indexrelid) 736 LEFT JOIN pg_catalog.pg_namespace n ON (n.oid = c.relnamespace) 737 LEFT JOIN $TSJOIN 738 WHERE 739 i.indisprimary IS TRUE 740 $whereclause 741 }; 742 743 my $sth = $dbh->prepare($pri_key_sql) or return undef; 744 $sth->execute(); 745 my $info = $sth->fetchall_arrayref()->[0]; Subsequent SQL that does not give any result is: 748 # Get the attribute information 749 my $indkey = join ',', split /\s+/, $info->[4]; 750 my $sql = qq{ 751 SELECT a.attnum, pg_catalog.quote_ident(a.attname) AS colname, 752 pg_catalog.quote_ident(t.typname) AS typename 753 FROM pg_catalog.pg_attribute a, pg_catalog.pg_type t 754 WHERE a.attrelid = '$info->[0]' 755 AND a.atttypid = t.oid 756 AND attnum IN ($indkey); 757 }; A possible solution is probably to cast c.oid to text so that it is treated as a string by perl. But this needs to be done in all such places where value of rowid is reused. Sundry Info: =============================================================================== # lsb_release -a Distributor ID: Debian Description: Debian GNU/Linux 7.0 (wheezy) Release: 7.0 Codename: wheezy # uname -a Linux development2 3.2.0-4-686-pae #1 SMP Debian 3.2.41-2 i686 GNU/Linux # perl -v | grep version This is perl 5, version 14, subversion 2 (v5.14.2) built for i486-linux-gnu-thread-multi-64int psql > select version(); PostgreSQL 9.1.3 on x86_64-unknown-linux-gnu, compiled by gcc (Debian 4.3.2-1.1) 4.3.2, 64-bit Regards, Rajesh Kumar Mallah Tel. 91-11-46710500 (Ext:303) Cell +919811255597 Website: http://www.tradeindia.com/ \|/ \|/ \|/ stop printing \|/ \|/ \|/ | | | start planting | | |
Subject: Re: [rt.cpan.org #85836] AutoReply: primary_key_info fails on 32bit system for tables where oid is > max value of signed 32bit int
Date: Mon, 3 Jun 2013 23:37:25 +0530 (IST)
To: bug-DBD-Pg [...] rt.cpan.org
From: Rajesh Kumar Mallah <mallah [...] tradeindia.com>
DBD::Pg version 2.19.2 regds mallah.
Thank you for the report. The fix was actually quite easy: we were forcing oids to an int via sv_setiv in dbdimp.c. A bad idea, and now removed. Git commit is 0d345d85ced9af6d804cbac79539ade4765eeab0 If you want to test your local copy, just remove the line from dbdimp.c containing PG_OID.
Subject: Re: [rt.cpan.org #85836] primary_key_info fails on 32bit system for tables where oid is > max value of signed 32bit int
Date: Thu, 22 Aug 2013 15:44:05 +0530 (IST)
To: bug-DBD-Pg [...] rt.cpan.org
From: Rajesh Kumar Mallah <mallah [...] tradeindia.com>
Dear Greg , Is it possible to solve this case: my ($table_oid) = $dbh->selectrow_array( q{SELECT oid FROM pg_class WHERE relname=? AND relnamespace=( SELECT oid FROM pg_namespace WHERE nspname=?) }, undef, $table, $db_schema); If we have the above line in a script that uses the latest version of DBD::Pg then also $table_oid will contain a truncated integer. So we are having to write above as: my ($table_oid) = $dbh->selectrow_array( q{SELECT oid::text FROM pg_class WHERE relname=? AND relnamespace=( SELECT oid FROM pg_namespace WHERE nspname=?) }, undef, $table, $db_schema); Regards, Rajesh Kumar Mallah Tel. 91-11-46710500 (Ext:303) Cell +919811255597 Website: http://www.tradeindia.com/ \|/ \|/ \|/ stop printing \|/ \|/ \|/ | | | start planting | | |
Show quoted text
> Is it possible to solve this case:
Yes, the abovementioned patch fixes that case. Tested and confirmed.