Skip Menu |
 

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

Report information
The Basics
Id: 118207
Status: resolved
Priority: 0/
Queue: DBD-mysql

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

Bug Information
Severity: Normal
Broken in: 4.032
Fixed in: 4.039



Subject: BIT fields are handled inconsistently between insert and select.
Download (untitled) / with headers
text/plain 590b
To insert into a proper value into BIT(8) column, you must first turn your data into a bit string with pack or vec, but to select it back out, you must use a normal integer: $dbh->do("create table bittest (lilbits bit(8))"); my $insert = $dbh->prepare("insert into bittest values (?)"); my $select = $dbh->prepare("select * from bittest where lilbits = ?"); $insert->execute(pack "n", 5); $insert->execute(pack "b", "101"); vec(my $bitstring, 0, 8) = 5; $insert->execute($bitstring); $select->execute(5); while (my $row = $select->fetch) { printf "%08b\n", ord $row->[0]; }
Download (untitled) / with headers
text/plain 1.1k
On Sob Okt 01 11:50:32 2016, COWENS wrote: Show quoted text
> To insert into a proper value into BIT(8) column, you must first turn > your data into a bit string with pack or vec, but to select it back > out, you must use a normal integer: > > $dbh->do("create table bittest (lilbits bit(8))"); > > my $insert = $dbh->prepare("insert into bittest values (?)"); > my $select = $dbh->prepare("select * from bittest where lilbits = ?"); > > $insert->execute(pack "n", 5); > $insert->execute(pack "b", "101"); > > vec(my $bitstring, 0, 8) = 5; > > $insert->execute($bitstring); > > $select->execute(5); > > while (my $row = $select->fetch) { > printf "%08b\n", ord $row->[0]; > }
Should be fixed by these commits: https://github.com/perl5-dbi/DBD-mysql/commit/702744529a9ff240b00af67983535e65822f3103 https://github.com/perl5-dbi/DBD-mysql/commit/8a11b95256176bac523735d04829aa9d0e95edf2 BIT type is by default returned as bit string, but with "SELECT BIN(col) ..." you can returns it as one-zero string. If you want to pass scalar as BIT type, you can use pack + DBI::SQL_BINARY type in bind_param. But see usage of BIT in unit tests from above commits...
Fixed in latest versions of DBD::mysql.


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.