Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

DBI gives "undef" for specific row

by hpeters (Initiate)
on Mar 11, 2014 at 15:45 UTC ( #1077865=perlquestion: print w/replies, xml ) Need Help??
hpeters has asked for the wisdom of the Perl Monks concerning the following question:

I have a somewhat weird problem... I'm connecting via FreeTDS/ODBC to a mssql-database; all works good, except: select * from sometable where somerow=1234> This ("anonymized") select gives me always "undef" for one specific row, despite its value:
$VAR1 = { 'row1' => 17, 'row2' => undef, 'row2' => '36688.00', 'row3' => '30328.50', 'row4' => 6762, 'row5' => 0, 'row6' => 12302 };
Doing exact the same select (copy & paste from log) in the sql-manager returns all values for row2. I know I'll get undef for NULL-rows, but this row isn't NULL! it has integer values like row4. Any hints?
DBI 1.631 DBD::ODBC 1.45 unixODBC-2.3.2 FreeTDS 0.91

Replies are listed 'Best First'.
Re: DBI gives "undef" for specific row
by mje (Curate) on Mar 11, 2014 at 16:50 UTC

    You example is a little confusing because you use the word "row" when it is a column. So I am assuming when you issue the select you have a problem with one of the columns is returned as undef and you don't expect it to be.

    Try running the smallest example of what you are doing but with the environment variable DBI_TRACE set like "export DBI_TRACE=DBD=x.log" and show me the log output (in x.log) after the prepare and up to the end of the fetching.

Re: DBI gives "undef" for specific row
by kcott (Chancellor) on Mar 11, 2014 at 21:50 UTC

    G'day hpeters,

    Welcome to the monastery.

    As already pointed out, you seem to be using the term "row" where you mean "column". Please provide a clarification on that.

    If $VAR1 represents a row, then you have columns with names like 'rowN'. That seems somewhat strange and leads me to wonder if $VAR1 really does represent a row. Again, please clarify.

    Assuming $VAR1 is a row and the keys shown are the column names, then you have two columns with the same name (i.e. 'row2'):

    'row2' => undef, 'row2' => '36688.00',

    Perhaps a typo by you or a wrong assumption by me: either way, a correction or further clarification is required.

    -- Ken

Re: DBI gives "undef" for specific row
by mwb613 (Sexton) on Mar 11, 2014 at 19:23 UTC
    Try selecting that column specifically like so:
    select row2 from sometable where somerow=1234
    Also, can you include your result fetch method in the post (fetchrow_hashref, fetchall_hashref, etc)?
Re: DBI gives "undef" for specific row
by Marshall (Abbot) on Mar 14, 2014 at 04:38 UTC
    First, it appears that your output means "column" instead of "row".

    It very well could be that Line["col"] does indeed => undef!

    The DBI will produce a "row" from your query. Each token is a 'column' in the SQL table.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1077865]
Approved by Corion
Front-paged by toolic
and a kettle whistles...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2018-05-22 00:44 GMT
Find Nodes?
    Voting Booth?