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. Advertisements

  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. Advertisements

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,448
  2. J Leonard
    Replies:
    4
    Views:
    14,025
    Mark Space
    Jan 19, 2008
  3. bigjojoi
    Replies:
    0
    Views:
    168
    bigjojoi
    Jul 1, 2003
  4. Sashafay

    Call PL/SQL procedure from Perl - DBI

    Sashafay, Sep 7, 2003, in forum: Perl Misc
    Replies:
    3
    Views:
    241
    Sashafay
    Sep 8, 2003
  5. John
    Replies:
    14
    Views:
    507
  6. JonL

    Piecewise fetching using perl dbi

    JonL, Feb 11, 2005, in forum: Perl Misc
    Replies:
    1
    Views:
    409
  7. Vance M. Allen

    Perl DBI / SQL Question

    Vance M. Allen, Sep 14, 2005, in forum: Perl Misc
    Replies:
    9
    Views:
    198
    A. Sinan Unur
    Sep 16, 2005
  8. Metre Meter
    Replies:
    7
    Views:
    1,013
    Metre Meter
    Aug 6, 2010
Loading...