[CDBI] Deep recursion on subroutine "Class::DBI::_flesh" ; Class::DBI::Pg

Dan Rowles d.rowles at outcometechnologies.com
Thu Jan 12 14:02:13 GMT 2006


Triggers are inherited. So, if you put triggers in your Person class, 
they will be called when you insert a Member.

So, you could put a trigger in the "Person" class, and an additional 
trigger containing only those things that you need to set up in the 
Member class, and that should just work.

Thanks,

Dan




Cedric Boudin wrote:
> Dan Rowles wrote:
> 
> 
>>I've had "deep recursion on _flesh" problems when I've had a
>>"before_create" trigger that calls accessor methods on my object.
>>Somethhing like:-
>>
>>__PACKAGE__->add_trigger("before_create" => sub {
>>    my $this = shift;
>>    $this->id(GenUUID()) unless $this->id;
>>});
>>
>>usually is the cause of the problem (for me at any rate).
> 
> 
> I needed also a trigger before create.
> But in my case I did not do it because I need it at the Person level.
> As the insert is done at member level (at least in this version of my
> thoughts, hence my "side questions")
> so to have it working
> I must put it at the member level and for the next child class of person
> on the same level as member I must have it again.
> this leads to same code in different places not so nice.
> So I did put my trigger in the db where by the way I have the same
> problem of inheritance :=)
> 
> so there are no before create trigger in cdbi for this class
> 
> 
>>If you do have this, then you have two options - only use calls to
>>"_attr" and "_attribute_store" in "before_create" triggers (a pain if
>>you want to re-use validation code), or you can try putting this piece
>>of code into your App::DBI class, and see if it fixes it:-
>>
>>sub _flesh {
>>    my $this = shift;
>>    if(ref($this) && $this->_undefined_primary) {
>>        $this->call_trigger("select");
>>        return $this;
>>    }
>>    return $this->SUPER::_flesh(@_);
>>}
>>
> 
> I tried this and magically it works I can catch my exception.
> I'll deeply impressed and grateful.
> 
> Have a succesfull 2006
> 
> cedric
> 
> 
> 
>>Hope this helps,
>>
>>Dan
>>
>>
>>
>>
>>
>>Cedric Boudin wrote:
>>
>>
>>>Dear list member,
>>>
>>>I do get this message by running my script:
>>>------
>>>Issuing rollback() for database handle being DESTROY'd without explicit
>>>disconnect() at /usr/local/share/perl/5.8.7/Ima/DBI.pm line 315.
>>>Deep recursion on subroutine "Class::DBI::_flesh" at
>>>/usr/local/share/perl/5.8.7/Class/DBI.pm line 818.
>>>Deep recursion on anonymous subroutine at
>>>/usr/local/share/perl/5.8.7/Class/DBI.pm line 830.
>>>------------------
>>>
>>>The roll back is triggered by an insertion violating a unique constraint
>>>on two columns in the inserted table.
>>>I do this on purpouse and want to catch the error with
>>>Exception::Class::DBI
>>>I'm using
>>>Class::DBI::Pg
>>>and do try to exploit the 'OOiness' of Postgres.
>>>Here is how I've structured the tables and the classes.
>>>DB
>>>on Top level: table Person, table additional_data
>>>underneath: table Member inherits Person, additional_data
>>>Class::DBI
>>>Top Level: App::DBI
>>>below:
>>>- App::Person isa App::DBI
>>>- App::Member isa App::Person
>>>
>>>the insert is done by like this
>>>my $member=App::Member->new()
>>>eval {
>>>    $member->insert({col1 =>'col1',col2=>'col2'..});
>>>}
>>>if ($@){
>>>...
>>>}
>>>
>>>in App::DBI I've configured my connection like this
>>>__PACKAGE__->connection("dbi:Pg:dbname=ego",
>>>                        'ego',
>>>                        'ego',
>>>                        { PrintError => 0,
>>>                          RaiseError => 0,
>>>                          HandleError => Exception::Class::DBI->handler
>>>                      });
>>>The autocommit is not set
>>>
>>>I never come back from my insert, and I suppose the recursion is
>>>somewhere deep in there.
>>>I never come to catch my exception.
>>>
>>>What am I doing wrong?
>>>
>>>Side questions:
>>>- Is "misusing" class::dbi with the Pg OO structure reasonnable
>>>- Is there a way to automagically enforce
>>>that in my above described construct the Class Member takes care of the
>>>member specific attribute of the member instance
>>>and that person class for it's attributes?
>>>
>>>in advance thank you for your future input
>>>
>>>cedric
>>>
>>>
>>>
>>>_______________________________________________
>>>ClassDBI mailing list
>>>ClassDBI at lists.digitalcraftsmen.net
>>>http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi
>>
>>
> 

-- 
Dan Rowles
Outcome Technologies

_________________________________

t: +44 (0)207 656 2460
f: +44 (0)709 230 6588
m: +44 (0)798 076 8143
e: d.rowles at outcometechnologies.com
w: http://www.outcometechnologies.com
BUPA House
15-19 Bloomsbury Way
London WC1A 2BA
_________________________________

***This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they are
addressed. If you receive this message in error, please return it to the
sender.***




More information about the ClassDBI mailing list