Bug#554489: DBD::Pg in Lenny mangles high bit characters with pg_server_prepare=0

Bryce Nesbitt bryce2 at obviously.com
Fri Nov 6 23:31:42 UTC 2009


Here's the one line patch, consistent with upstream 
http://rt.cpan.org/Public/Bug/Display.html?id=39390
Plus an addition to the test harness which I highly encourage you to 
raft along.



*** DBD-Pg-2.8.7/quote.c    2009-11-06 14:54:10.000000000 -0800
--- DBD-Pg-2.8.7_Orig/quote.c    2008-05-08 19:14:43.000000000 -0700
***************
*** 205,211 ****
              *result++ = '\\';
          }
          else if (*string < 0x20 || *string > 0x7e) {
!             (void) snprintf((char *)result, 6, "\\\\%03o", (unsigned 
char)*string++);
              result += 5;
          }
          else {
--- 205,211 ----
              *result++ = '\\';
          }
          else if (*string < 0x20 || *string > 0x7e) {
!             (void) snprintf((char *)result, 6, "\\\\%03o", *string++);
              result += 5;
          }
          else {
diff -C3 -r DBD-Pg-2.8.7/t/06bytea.t DBD-Pg-2.8.7_Orig/t/06bytea.t
*** DBD-Pg-2.8.7/t/06bytea.t    2009-11-06 15:03:28.000000000 -0800
--- DBD-Pg-2.8.7_Orig/t/06bytea.t    2008-07-09 15:26:00.000000000 -0700
***************
*** 17,23 ****
  if (! defined $dbh) {
      plan skip_all => 'Connection to database failed, cannot continue 
testing';
  }
! plan tests => 11;
 
  isnt ($dbh, undef, 'Connect to database for bytea testing');
 
--- 17,23 ----
  if (! defined $dbh) {
      plan skip_all => 'Connection to database failed, cannot continue 
testing';
  }
! plan tests => 7;
 
  isnt ($dbh, undef, 'Connect to database for bytea testing');
 
***************
*** 28,34 ****
 
  my ($sth, $t);
 
- #################################################################
  $sth = $dbh->prepare(q{INSERT INTO dbd_pg_test (id,bytetest) VALUES 
(?,?)});
 
  $t='bytea insert test with string containing null and backslashes';
--- 28,33 ----
***************
*** 41,55 ****
  $t='bytea (second) insert test with string containing a single quote';
  ok ($sth->execute(402, '\''), $t);
 
- my ($binary_in, $binary_out);
- $t='store binary data in BYTEA column';
- for(my $i=0; $i<256; $i++) { $binary_out .= chr($i); }
- $sth->{pg_server_prepare} = 0;
- ok ($sth->execute(403, $binary_out), $t);
- $sth->{pg_server_prepare} = 1;
- ok ($sth->execute(404, $binary_out), $t);
-
- #################################################################
  $t='Received correct text from BYTEA column with backslashes';
  $sth = $dbh->prepare(q{SELECT bytetest FROM dbd_pg_test WHERE id=?});
  $sth->execute(400);
--- 40,45 ----
***************
*** 61,76 ****
  $byte = $sth->fetchall_arrayref()->[0][0];
  is ($byte, '\'', $t);
 
- $t='compare binary data in bytea row 403';
- $sth->execute(403);
- ($binary_in) = $sth->fetchrow_array();
- ok( $binary_in eq $binary_out, $t );
- $t='compare binary data in bytea row 404';
- $sth->execute(404);
- ($binary_in) = $sth->fetchrow_array();
- ok( $binary_in eq $binary_out, $t );
-
- #################################################################
  $t='quote properly handles bytea strings';
  my $string = "abc\123\\def\0ghi";
  my $result = $dbh->quote($string, { pg_type => PG_BYTEA });
--- 51,56 ----






More information about the pkg-perl-maintainers mailing list