[CDBI] Re: Deep recursion

Arshavir Grigorian grigorian at gmail.com
Fri Aug 17 02:13:00 BST 2007


Edward,

Thanks for the comments. You were right, it didn't have anything to do
with naming.

After a lot of looking, I found the problem. In my code

	foreach my $column (keys %$href) {
	    $obj->set($column => $href->{$column});
	}

among others, I also had an 'id' key in the $href hash (for later use)
and was effectively setting/updating the primary key of the table.
Removing that key fixed the issue. I can't think of any instances
where it would be necessary to modify a primary key, but with that
being said, there should definitely be an error/warning message
generated when someone tries to do that.

HTH.




On 8/8/07, Edward J. Sabol <sabol at alderaan.gsfc.nasa.gov> wrote:
> Dave Howorth asked:
> > Are you saying that there's a problem with naming a column 'id' [...]?
>
> There shouldn't be. Maybe there was at some point in the history of
> Class::DBI and that's what Schwern is remembering, but the latest code checks
> to see if the column name is 'id' and appears to do the right thing when
> creating the accessors. If it doesn't, someone should file a bug report.
>
>
> Arshavir Grigorian wrote:
> >> 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);
> [..]
> >> Also, I noticed that this problem occurs only on objects that have
> >> just been created/inserted (vs objects that one gets through a
> >> retrieve/search operation).
> >>
> >> $obj = TAB->retrieve(...); $obj->id; - works fine.
>
> I think the fact that your primary key is named "id" is a red herring.
> Are you using a 'before_create' trigger to set the date? It sure sounds like
> it. If so, Dan Rowles posted a workaround to this mailing list on 12 Jan
> 2006. If not, you might want to look at that thread anyway.
>
> Hope this helps,
> Ed



More information about the ClassDBI mailing list