[CDBI] Deep recursion

Arshavir Grigorian grigorian at gmail.com
Wed Aug 8 04:31:06 BST 2007


Thanks, Michael.

The reason I need access to the primary key is that I have the
following sql to set the sysdate (from the wiki site):

__PACKAGE__->set_sql(set_sysdate => qq{
  UPDATE __TABLE__
     SET %s = now()
   WHERE __IDENTIFIER__
});

and to execute this I have to do:

$obj->sql_set_sysdate("some_dt")->execute($obj->id);

Now, considering that I am calling sql_set_sysdate() on the object
itself, shouldn't it be smart enough to know that it should update the
record that $obj points to? Is there a better way to do this?

Thanks.


On 8/7/07, Michael G Schwern <schwern at pobox.com> wrote:
> Arshavir Grigorian wrote:
> > Hi,
> >
> > I have a table with a primary key called "id". When I make an insert
> > into that table, then try to get the primary key, I get into deep
> > recursion:
> >
> > __PACKAGE__->table('tab');
> > __PACKAGE__->columns(Primary => 'id');
> > __PACKAGE__->columns(All => qw/id .../);
> >
> > ...
> >
> > my $obj = TAB->insert($href);
> > my $id = $obj->id;
> >
> > And in the logs, I see a lot of:
> >
> >         Class::DBI::_flesh('TAB=HASH(0x9102a08)', 'Primary') called at
> > /usr/local/share/perl/5.8.7/Class/DBI.pm line 844
> >         Class::DBI::get('TAB=HASH(0x9102a08)', 'id') called at
> > /usr/local/share/perl/5.8.7/Class/Accessor.pm line 393
> >         Class::Accessor::__ANON__('TAB=HASH(0x9102a08)') called at
> > /usr/local/share/perl/5.8.7/Class/DBI.pm line 857
>
> If you name a column accessor "id" it blows over the very important built-in
> method "id".  Granted it would be nice if it warned you about this very common
> mistake.
>
> The following covers how to map columns to differently named accessors.
> http://search.cpan.org/~tmtm/Class-DBI-v3.0.16/lib/Class/DBI.pm#Changing_Your_Column_Accessor_Method_Names
>



More information about the ClassDBI mailing list