Skip Menu |
 

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

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

People
Owner: greg [...] turnstep.com
Requestors: kev [...] brantaero.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 2.10.0
Fixed in: 2.14.0



Subject: boolean conversion to 0 and 1 rather than '0' and '1'
Download (untitled) / with headers
text/plain 676b
Hi, I'm running ActiveState Perl 5.10 build 1004 on Windows Server 2003 Standard Edition SP2. It would be useful if there was some way to have boolean values come back from the database as the number values 0 or 1 rather than as the string values "0" and "1", because if you pass these directly to a JSON encoder, you lose the boolean meaning in JavaScript because both strings, being non-empty, evaluate to true. Detailed story here: http://stackoverflow.com/questions/1087308/why-cant-i-properly-encode-a-boolean-from-postgresql-via-jsonxs-via-perl I'm not clear on the correct way to modify quote.c to have this happen, but hopefully it's a simple change? Thanks, Kev
Download (untitled) / with headers
text/plain 866b
Show quoted text
> It would be useful if there was some way to have boolean values come > back from the database as the number values 0 or 1 rather than as the > string values "0" and "1", because if you pass these directly to a > JSON > encoder, you lose the boolean meaning in JavaScript because both > strings, being non-empty, evaluate to true.
Also this would bring it in line with the documentation, which says: "The current implementation of PostgreSQL returns 't' for true and 'f' for false. From the Perl point of view, this is a rather unfortunate choice. DBD::Pg therefore translates the result for the BOOL data type in a Perlish manner: 'f' becomes the number 0 and 't' becomes the number 1." Numbers and strings being distinct in Perl, this isn't actually currently true of DBD::Pg, so if it's too much trouble to change DBD::Pg, the docs should probably be changed.
Download (untitled) / with headers
text/plain 1.1k
On Mon Jul 06 11:21:40 2009, Kevin_Field wrote: Show quoted text
> Hi, > > I'm running ActiveState Perl 5.10 build 1004 on Windows Server 2003 > Standard Edition SP2. > > It would be useful if there was some way to have boolean values come > back from the database as the number values 0 or 1 rather than as the > string values "0" and "1", because if you pass these directly to a > JSON > encoder, you lose the boolean meaning in JavaScript because both > strings, being non-empty, evaluate to true. > > Detailed story here: > > http://stackoverflow.com/questions/1087308/why-cant-i-properly-encode- > a-boolean-from-postgresql-via-jsonxs-via-perl > > I'm not clear on the correct way to modify quote.c to have this > happen, > but hopefully it's a simple change? > > Thanks, > Kev
Actually, this appears to be a bit worse than I thought. If I do a "select 0" or "select 0::integer" it *still* gets output as a string, even though $sth->{TYPE}->[0] is equal to SQL_INTEGER: my $sth = $dbh->prepare("select 5"); $sth->execute; my @vals = $sth->fetchrow_array; use Data::Dumper; # die Dumper($vals[0]); # dies with "$VAR1 = '5';" die Dumper (5); # dies with "$VAR1 = 5;" Kev
Thanks for the report, I'll look into this, it should be possible for most types.
From: kev [...] brantaero.com
Download (untitled) / with headers
text/plain 161b
On Tue Jul 07 10:57:22 2009, greg@turnstep.com wrote: Show quoted text
> Thanks for the report, I'll look into this, it should be possible for > most types.
Super. Thanks! Kev
Download (untitled) / with headers
text/plain 111b
Applied a fix in r13039, please try it out if you can. Otherwise, it should appear in the next version, 2.14.0
From: kev [...] brantaero.com
Download (untitled) / with headers
text/plain 267b
On Sun Jul 12 14:03:59 2009, greg@turnstep.com wrote: Show quoted text
> Applied a fix in r13039, please try it out if you can. Otherwise, it > should appear in the next version, 2.14.0
Sorry, I'm not equipped for it, but I'll try out 2.14.0 as soon as there's a .ppd. Thanks again!


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.