Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Class::DBI strangeness...

by duct_tape (Hermit)
on Dec 19, 2003 at 20:47 UTC ( #315907=note: print w/replies, xml ) Need Help??


in reply to Class::DBI strangeness...

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://315907]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (11)
As of 2019-10-16 12:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?