Skip Menu |
 

This queue is for tickets about the Tie-DBI CPAN distribution.

Report information
The Basics
Id: 19833
Status: resolved
Priority: 0/
Queue: Tie-DBI

People
Owner: TODDR [...] cpan.org
Requestors: jonathan.santaana [...] nzx.com
Cc:
AdminCc:

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

Attachments


Subject: Tie::DBI strips trailing spaces from stored values
MIME-Version: 1.0
X-Mailer: MIME-tools 5.418 (Entity 5.418)
X-RT-Original-Encoding: utf-8
Content-Type: multipart/mixed; boundary="----------=_1150089386-16979-2"
Content-Length: 0
Content-Type: text/plain; charset="utf8"
Content-Disposition: inline
Content-Transfer-Encoding: binary
Content-Length: 1433
Download (untitled) / with headers
text/plain 1.3k
A string with trailing spaces stored in a hash tied via Tie::DBI to an SQL database will, when read back, have the spaces removed. Tested on: Perl 5.6.1, Tie::DBI 1.02, DBI 1.21, MySQL 3.23.49, DBD::mysql 1.2216. All packages are the standard ones from the Debian "woody" distribution, except Tie::DBI, which was installed from CPAN. (It's not included in woody.) This is a result of the DBI ChopBlanks attribute, so can be worked around by extracting the database handle for the tie and performing $dbh->{'ChopBlanks'} = 0; however, the documentation for my version of DBI says that this value defaults to false, so either the documentation is wrong or Tie::DBI is explicitly setting it to true. If the latter is true, it's very unintuitive, and also violates the DBI recommendations, as it breaks the emulation of standard untied Perl hashes. Even if it turns out to be a problem with the DBI defaults, the DBI docs recommend that applications wanting specific behaviour set the attribute themselves. Thus it should still be patched in Tie::DBI. Tested only on MySQL, but as I've confirmed that the trailing spaces are still stored in the database and that explicitly setting ChopBlanks to 0 fixes the problem, I think it's reasonable to assume the same problem will show up with other database backends. A small script to reproduce the problem is attached; it requires Tie::DBI and an appropriately-configured database.
Subject: tie-dbi-bug.pl
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="----------=_1150089386-16979-1"
X-Mailer: MIME-tools 5.418 (Entity 5.418)
Content-Length: 0
Content-Type: text/plain; charset="utf8"
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 0
Content-Type: application/octet-stream; name="tie-dbi-bug.pl"
Content-Disposition: inline; filename="tie-dbi-bug.pl"
Content-Transfer-Encoding: base64
Content-Length: 1088
Download tie-dbi-bug.pl
text/x-perl 1k
#!/usr/bin/perl -w # demonstrates space-stripping bug in Tie::DBI 1.02 # # assumes that a database is already configured, and that a table named # "hash" exists which has at least two columns: "hashkey" for keys and # "hashval" for values. Do not use TEXT or VARCHAR as the "hashval" # column type; MySQL at least strips trailing spaces in the actual # database for these types, whereas BLOB or VARBINARY will store the # trailing spaces correctly (though Tie::DBI will still strip them.) use strict; use Tie::DBI; use constant TEST_STRING => ' extra spaces '; use constant TIE_DETAILS => { db => 'mysql:depth_test', table => 'hash', key => 'hashkey', user => 'depth_test', password => 'depth_test', CLOBBER => 2 }; my %hash; my ($before, $after); my $dbh; tie %hash, 'Tie::DBI', TIE_DETAILS or die; # uncomment to work around the bug #$dbh = tied(%hash)->dbh; #$dbh->{ChopBlanks} = 0; $before = TEST_STRING; $hash{1} = { hashval => $before }; $after = $hash{1}->{'hashval'}; print "Before: [$before]\n"; print "After : [$after]\n";
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-26544-1269890708-489.19833-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 644
Download (untitled) / with headers
text/plain 644b
I added this test to DBI.t. I believe it re-produces your problem as you suggest. diff --git a/t/DBI.t b/t/DBI.t index 1127a8b..32fd892 100644 --- a/t/DBI.t +++ b/t/DBI.t @@ -166,3 +166,10 @@ SKIP: { ok($h{strawberries}->{quantity}=42); ok($h{strawberries}->{quantity}=42); # make sure update statement works when nothing changes is($h{strawberries}->{quantity}, 42); + +# RT 19833 - Trailing space inappropriatley stripped. +use constant TEST_STRING => ' extra spaces '; +my $before = TEST_STRING; +$h{strawberries}->{description} = $before; +my $after = $h{strawberries}->{description}; +is($after, $before, "blanks aren't chopped");
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-26546-1269897092-1599.19833-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 41
Thanks for your report.. Resolved in 1.03


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.