Hello,

In the Class::DBI pod there is a section about LAZY POPULATION. Basically it loads as little as possible into the object in hopes to increase performance.

Assuming you specified all the columns that you want in the All (or Essential) group in your columns() call, whenever you make a call to any column accessor it will load the rest of them into object as well. So you can change your code to the following without worrying that it is querying the database for every column:

... foreach ( $usr->columns ) { $output .= "<b>$_</b>; " . $usr->$_ . "<br>"; } ...

To see this in action, call $usr->upusername and then dump the $usr object and in theory it should also have the rest of the columns in it as well.

I have also noticed that when you call create() with all the columns, it only returns back an object with the primary key in it. I assume it does this type of stuff in case you have triggers set up in your database that did something with the columns after you inserted them. Just a guess though...

Take my comments with a grain of salt... I've only been playing around with CDBI for less than a week, so I am not too experienced with it. But I hope I am of some help.


Regards,
Bradley C Bailey

In reply to Re: Class::DBI strangeness... by duct_tape
in thread Class::DBI strangeness... by jdtoronto

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.