[CDBI] Re: custom accessor problem?

Edward J. Sabol sabol at alderaan.gsfc.nasa.gov
Wed Mar 14 15:48:15 GMT 2007

Adam wrote:
> The placeholder is only really relevant for INSERT/UPDATEs - I'm
> specifically interested in SELECTs here, sorry.

Oh, I thought that part of your original post was about INSERT/UPDATEs. My
mistake. Still, it would be interesting to know if specifying the placeholder
like that would allow one to UPDATE datetime fields or not.

Also, I was wondering if you should use 'precise=convert(char(26),
topic_updated_dt, 109)' for the column name instead of 'convert(char(26),
topic_updated_dt, 109)'. There are a few places in the Class::DBI code
that uses $sth->{NAME_lc}, so giving the field some kind of name might be
needed. But it sounds like you got it working without that, so I guess not!

>> Not sure what you mean. The examples in that first Wiki page are using
>> custom SQL.
> Yes, but I just wanted an accessor rather than a mutator - those
> examples are all about setting date columns, not reading them in
> 'special' ways.

The concept is similar though. Instead of customizing the MakeNewObj SQL
statement as described in the first wiki page, one would customize the
Retrieve SQL statement and maybe RetrieveAll and some others. (I mentioned
this in passing in a previous e-mail.) It quickly becomes very messy,
however. The new method using a Class::DBI::Column object is much better,
assuming it works.

>  sub accessor_name_for {
>     my ($class, $column) = @_;
>     $column =~ s/^customer//;
>     return $column;
>   }
> Note that the code says $column->accessor; the docs just say $column.

Yes, it does appear from the code that accessor_name_for() is passed a
Class::DBI::Column object now? The docs don't really take that into
consideration. You might want to file a bug report with Tony.

> Thanks for all your help, it's always useful to have encouragement to
> delve into the code and work out what exactly is going on :-)

Good, glad to hear you got it working. Just for the record, perhaps you could
you put the whole picture together and post the solution on the wiki? (Or
send it to me and I'll post it, if don't want to go through the hassle of
creating an account on the wiki.) Somewhere at the bottom of
http://wiki.class-dbi.com/wiki/Setting_system_date_fields would be fine, I
think. Or if you want to start a new page....


More information about the ClassDBI mailing list