Fetching SQL boolean values with Perl DBI?

Discussion in 'Perl Misc' started by Dave Stallard, Mar 20, 2011.

  1. 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
    Dave Stallard, Mar 20, 2011
    #1
    1. Advertising

  2. Dave Stallard

    Uri Guttman Guest

    >>>>> "DS" == Dave Stallard <> writes:

    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

    --
    Uri Guttman ------ -------- http://www.sysarch.com --
    ----- Perl Code Review , Architecture, Development, Training, Support ------
    --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
    Uri Guttman, Mar 21, 2011
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dna
    Replies:
    1
    Views:
    1,264
  2. ulloa
    Replies:
    1
    Views:
    517
    Juha Laiho
    Jul 22, 2004
  3. J Leonard
    Replies:
    4
    Views:
    12,632
    Mark Space
    Jan 19, 2008
  4. JonL

    Piecewise fetching using perl dbi

    JonL, Feb 11, 2005, in forum: Perl Misc
    Replies:
    1
    Views:
    267
  5. Metre Meter
    Replies:
    7
    Views:
    358
    Metre Meter
    Aug 6, 2010
Loading...

Share This Page