So, when a table has x-columns, but some of them are empty, nul,
while (@results = $sth->fetchrow_array()) {.....}
does NOT initialize all the x-elements of @results???

According to the description of fetchrow_array in the DBI manual:

     Null fields are returned as "undef" values in the list.
This seems reasonable. If you really want to use "SELECT * ..." as your SQL statement, maybe you'd rather use fetchrow_hashref: it might be a little slower in terms of runtime, but then you'll have a little more structure in what you get back, so you can easily test the hashref elements for "undef" values and know which fields are null.

Spending that extra runtime will save you from having to get serious about your SQL usage -- i.e. doing things like naming the specific fields that you want from the query, using "SELECT IF(field1,field1,'Null_field1'), IF(field2,field2,'Null_field2') ... " or similar nonsense to make sure that all returned fields get defined values. What a pain. :)

(update: Actually, the proper SQL nonsense to use would most likely be something like SELECT IFNULL(field1,'Null_field1'), IFNULL(field2,'Null_field2')..." -- which will return empty strings and zeros when "non-null" fields are set to those values.)


In reply to Re: Simple db select output script hanging up. by graff
in thread Simple db select output script hanging up. by punch_card_don

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.