Skip Menu |

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

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

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

Bug Information
Severity: Important
Broken in: 3.6.2
Fixed in: 3.8.1



Subject: $dbh->do() function has problem with encoding
Here is test script: use strict; use warnings; use DBI; my $dbh = DBI->connect("dbi:Pg:dbname=postgres", "", ""); $dbh->do("CREATE TEMPORARY TABLE t(s VARCHAR(10))"); $dbh->do("INSERT INTO t(s) VALUES('\xC3\xA1')"); my ($val1) = $dbh->selectrow_array("SELECT s FROM t"); print 'do - ' . ($val1 eq "\xC3\xA1" ? 'OK' : 'FAIL') . ': ' . (join ', ', map ord, split //, $val1) . "\n"; $dbh->do("DROP TABLE t"); $dbh->do("CREATE TEMPORARY TABLE t(s VARCHAR(10))"); my $sth = $dbh->prepare("INSERT INTO t(s) VALUES('\xC3\xA1')"); $sth->execute(); my ($val2) = $dbh->selectrow_array("SELECT s FROM t"); print 'prepare+execute - ' . ($val2 eq "\xC3\xA1" ? 'OK' : 'FAIL') . ': ' . (join ', ', map ord, split //, $val2) . "\n"; $dbh->do("DROP TABLE t"); It inserts two characters C3 (LATIN CAPITAL LETTER A WITH TILDE) and A1 (INVERTED EXCLAMATION MARK) into database, then fetches it and checks that inserted value is the same as fetched. Plus prints ordinals of those characters (in decimal notation). There are two INSERT variants, one via do() and one via prepare()+execute(). Apparently, that variant via do() does not work and returns different data as inserted. Variant via prepare()+execute() is working fine. Here is output from that script with DBD::Pg version 3.6.2: do - FAIL: 225 prepare+execute - OK: 195, 161 195 in dec is C3 in hex and 161 in dec is A1 in hex, so output from prepare()+execute() is OK. I consider this a bug as do() should be really just equivalent of prepare()+execute().
Can duplicate, but no easy fix yet. We sling around SVs and char*s with abandon, and something gets the UTF-8 right for prepare, but not for quickexec.
On Str Sep 20 16:52:41 2017, TURNSTEP wrote: Show quoted text
> Can duplicate, but no easy fix yet. We sling around SVs and char*s > with abandon, and something gets the UTF-8 right for prepare, but not > for quickexec.
I guess problem is probably there: https://metacpan.org/source/TURNSTEP/DBD-Pg-3.6.2/Pg.xs#L319 SV* instead of char* Plus usage of pg_rightgraded_sv() like there: https://metacpan.org/source/TURNSTEP/DBD-Pg-3.6.2/dbdimp.c#L1570
On Ned Sep 24 13:17:37 2017, PALI wrote: Show quoted text
> On Str Sep 20 16:52:41 2017, TURNSTEP wrote:
> > Can duplicate, but no easy fix yet. We sling around SVs and char*s > > with abandon, and something gets the UTF-8 right for prepare, but not > > for quickexec.
> > I guess problem is probably there: > https://metacpan.org/source/TURNSTEP/DBD-Pg-3.6.2/Pg.xs#L319 > > SV* instead of char* > > Plus usage of pg_rightgraded_sv() like there: > https://metacpan.org/source/TURNSTEP/DBD-Pg-3.6.2/dbdimp.c#L1570
In pull request https://github.com/bucardo/dbdpg/pull/49 is fix for this issue.