[CDBI] Re: custom accessor problem?

Edward J. Sabol sabol at alderaan.gsfc.nasa.gov
Mon Mar 12 19:44:54 GMT 2007

Adam wrote:
> OK, looking at that again it breaks some code with using a custom
> accessor_name_for sub. Reverting line 344 and adding the following line
> around 362 (after the foreach my $type (keys %method) {}) works better
> - leaving the custom accessor ($acc) method in place, but adding an
> extra one based on $default_accessor as well.
> $class->_make_method("${default_accessor}",
> $class->make_ro_accessor($col->name_lc));
> Any thoughts?

Instantiating your own Class::DBI::Column object is probably the way of the
future (Tony has said a few times that he'd like to support things like this
and Class::DBI v3.0.x releases have been heading in that direction), but my
guess is that future has not yet been realized.

> my $topic_precise_updated_dt = Class::DBI::Column->new(
>    'convert (char(26), topic_updated_dt, 109)' => {
>      accessor => 'precise',
>    }
> );

The only documented argument to the Class::DBI::Column->new() method
currently is a single parameter name. Passing in other options is dangerous
territory. Michael Schwern is probably fuming at the thought of using such an
"undocumented feature." :-) It might be worth opening up a request at
<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Class-DBI> with severity "wishlist"
to see what Tony suggests. At a minimum, I *think* you probably need to pass
in a value for the 'placeholder' as well, something like the following:

my $topic_precise_updated_dt = Class::DBI::Column->new(
    'convert (char(26), topic_updated_dt, 109)' => {
     accessor => 'precise',
     placeholder => 'convert(datetime,?)',

It still may not work, however.

Dealing with DBMS-specific datetime fields can be done using more
traditional, alternative means, but it's messy. You have to override the SQL
statements for Retrieve, RetrieveAll, MakeNewObj, etc. and possibly define
your own SQL statement for updating the value (if you need that). There are a
couple entries in the CDBI Cookbook that you should read:


The first entry could use more fleshing out, however, and only the caveat
about datetime primary keys in the second entry is relevant to you as a
Sybase user.

Hope this helps,

More information about the ClassDBI mailing list