Fetching SQL boolean values with Perl DBI?

D

Dave Stallard

I'm working with a MySQL database via Perl DBI, and want to fetch the
value of an attribute of SQL boolean type. I would naturally imagine
this could come back as '0' or '1', but what comes back is instead
something weird that prints as '^@' or '^A' depending upon whether
it's true or false (I forget which is which). This thing, whatever
it is, appears to be a scalar, not a reference, but I don't know how
to refer to it in Perl. I'm using fetchrow_hashref, but I don't
think it matters.

Does anybody know what's going on here? (Apologies if there is a
more appropriate Perl DBI newsgroup which I missed).

thanks,
Dave
 
U

Uri Guttman

DS> I'm working with a MySQL database via Perl DBI, and want to fetch the
DS> value of an attribute of SQL boolean type. I would naturally imagine
DS> this could come back as '0' or '1', but what comes back is instead
DS> something weird that prints as '^@' or '^A' depending upon whether
DS> it's true or false (I forget which is which). This thing, whatever
DS> it is, appears to be a scalar, not a reference, but I don't know how
DS> to refer to it in Perl. I'm using fetchrow_hashref, but I don't
DS> think it matters.

you are getting back binary values for 0 and 1 in a char sized int. you
can unpack them into perl integers and use them as such. you could also
convert them other ways which i won't go into here.

uri
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Piecewise fetching using perl dbi 1
Arithmetic with Boolean values 15
DBI problems 4
How to get all values of an object 1
Problem installing DBI 2
DBI MS SQL connection error 2
DBI 2
Boolean Regexp with perlre 12

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top