Subject: | BIT fields are handled inconsistently between insert and select. |
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];
}