[CDBI] Null Column Causing Repeated DB Calls

Edward J. Sabol Edward.J.Sabol at nasa.gov
Fri Feb 26 19:13:40 GMT 2010

Eric wrote:
> The problem appears to be that calls to the accessors for columns with null
> values is the cause for the additional request to the database. That means
> that even an assignment, conditional on a "true" value as in
> my $x = $obj->offending_attribute if $obj->offending_attribute;
> Still hits the db to get the value, regardless of whether the column is in
> the Essential or Others column groups.

Maybe CDBI does that because it's possible the value in the database has been
changed since object instantiation, but it could very well be unintentional.
You could try submitting a bug report to RT, but don't expect a quick
response from Tony. I doubt he'd consider it important behavior to change
because it would be hard to develop a failing test case for it.

Database query efficiency wasn't a major design goal for CDBI. It's not for
most ORMs actually, but some are more efficient than others. I think CDBI's
design goals were more about correctness and simplicity/elegance (both from
an implementation point of view and a API point of view). If you need a very
efficient (but more complex) ORM, then Rose::DB::Object or maybe DBIx::Class
might be a better choice for you.

> I wound up doing this:
> But it seems that I'd have to do that for every column that could ever
> contain a NULL value.

That seems like a bad idea to me. I wouldn't recommend it.


More information about the ClassDBI mailing list