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

[prev] [thread] [next] [Date index for 2006/01/26]

From: Dan Fisher
Subject: [CDBI] Deep recursion on subroutine "Class::DBI::_flesh"
Date: 17:07 on 26 Jan 2006
--===============1279769414==
Content-Type: multipart/alternative; 
	boundary="----=_Part_49870_7004149.1138295262461"

------=_Part_49870_7004149.1138295262461
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

I had been running into this error (under CDBI 3.0.14):

Deep recursion on subroutine "Class::DBI::_flesh" at
/usr/lib/perl5/site_perl/5.8.5/Class/DBI.pm line 837.
Deep recursion on anonymous subroutine at
/usr/lib/perl5/site_perl/5.8.5/Class/DBI.pm line 849.

and while I saw this referenced earlier on the mailing list, my problem did
not stem from triggers, so I had to go out on my own to solve it.

First, a program that demonstrates the error:
---------------------------------------------------------------------------=
-------------------------------------
#!/usr/bin/perl

use strict;

package Person;

# Schema:
# CREATE TABLE test_table ( id integer not null primary key auto_increment,
name varchar(254) );

use base qw/Class::DBI/;

__PACKAGE__->connection('dbi:mysql:test', 'test', '12345', {AutoCommit =3D>=
 1,
RaiseError =3D> 1, PrintError =3D> 1});
__PACKAGE__->table('test_table');
__PACKAGE__->columns( Primary =3D> qw/
        id
/);
__PACKAGE__->columns( All =3D> qw/
        id
        name
/);

package main;

my $person_1 =3D Person->insert({});
print $person_1->name."\n";
$person_1->delete();

print '$person_1 created and deleted'."\n";

my $person_2 =3D Person->construct();
print $person_2->name."\n";

print '$person_2 created and accessed'."\n";
print 'Program Completed'."\n";
---------------------------------------------------------------------------=
-------------------------------------

When I run this, I get the following results:

$person_1 created and deleted
Deep recursion on subroutine "Class::DBI::_flesh" at
/usr/lib/perl5/site_perl/5.8.5/Class/DBI.pm line 837.
Deep recursion on anonymous subroutine at
/usr/lib/perl5/site_perl/5.8.5/Class/DBI.pm line 849.

...
and the program never finishes.

---------------------------------------------------------------------------=
-------------------------------------
I've found that the problem is that the 'get' method doesn't have any idea
about what columns it can potentially grab... While this is set up in
'insert/create', it is not set up in 'construct'. Now this might be by
design, but I really like to have an object (with all the methods already
written) without necessarily inserting it into the DB, and 'construct' seem=
s
to be the way to get that object.

My solution is primitive and I'll bet it could be optimized using the CDBI
internal API:
In 'Person' override the 'construct' method like this:

sub construct {
        my $class =3D shift;
        my $value_href =3D shift;
        my $no_value_href =3D {map {$_ =3D> ''} $class->columns};
        my $self =3D $class->SUPER::construct($no_value_href);

        my %value_hash =3D %{$value_href} if $value_href;
        $self->set(%value_hash);
        return $self;
}

Now, *all* the columns are initialized... Not just the ones sent values, an=
d
the program above will finish.

Any thoughts on this? Do I need to put this method in a base class that all=
l
CDBI classes will inherit from or is there any chance that this behavior ca=
n
be integrated into CDBI-proper?

Thank you for your time,
Daniel Fisher

------=_Part_49870_7004149.1138295262461
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

I had been running into this error (under CDBI 3.0.14):<br><br>Deep recursi=
on on subroutine &quot;Class::DBI::_flesh&quot; at /usr/lib/perl5/site_perl=
/5.8.5/Class/DBI.pm line 837.<br>Deep recursion on anonymous subroutine at =
/usr/lib/perl5/site_perl/5.8.5/Class/DBI.pm line 849.
<br><br>and while I saw this referenced earlier on the mailing list, my pro=
blem did not stem from triggers, so I had to go out on my own to solve it.<=
br><br>First, a program that demonstrates the error:<br>-------------------=
---------------------------------------------------------------------------=
------------------
<br>#!/usr/bin/perl<br><br>use strict;<br><br>package Person;<br><br># Sche=
ma:<br># CREATE TABLE test_table ( id integer not null primary key auto_inc=
rement, name varchar(254) );<br><br>use base qw/Class::DBI/;<br><br>__PACKA=
GE__-&gt;connection('dbi:mysql:test', 'test', '12345', {AutoCommit =3D&gt; =
1, RaiseError =3D&gt; 1, PrintError =3D&gt; 1});
<br>__PACKAGE__-&gt;table('test_table');<br>__PACKAGE__-&gt;columns( Primar=
y =3D&gt; qw/<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; id<br>/);<br>__=
PACKAGE__-&gt;columns( All =3D&gt; qw/<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp; id<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<br>/);<br><=
br>package main;<br><br>my $person_1 =3D Person-&gt;insert({});
<br>print $person_1-&gt;name.&quot;\n&quot;;<br>$person_1-&gt;delete();<br>=
<br>print '$person_1 created and deleted'.&quot;\n&quot;;<br><br>my $person=
_2 =3D Person-&gt;construct();<br>print $person_2-&gt;name.&quot;\n&quot;;
<br><br>print '$person_2 created and accessed'.&quot;\n&quot;;<br>print 'Pr=
ogram Completed'.&quot;\n&quot;;<br>---------------------------------------=
-------------------------------------------------------------------------
<br>
<br>When I run this, I get the following results:<br><br>$person_1 created =
and deleted<br>Deep recursion on subroutine &quot;Class::DBI::_flesh&quot; =
at /usr/lib/perl5/site_perl/5.8.5/Class/DBI.pm line 837.<br>Deep recursion =
on anonymous subroutine at /usr/lib/perl5/site_perl/5.8.5/Class/DBI.pm line=
 849.
<br><br>...<br>and the program never finishes.<br><br>---------------------=
---------------------------------------------------------------------------=
----------------<br>

I've found that the problem is that the 'get' method doesn't have any idea =
about what columns it can potentially grab... While this is set up in 'inse=
rt/create', it is not set up in 'construct'. Now this might be by design, b=
ut I really like to have an object (with all the methods already written) w=
ithout necessarily inserting it into the DB, and 'construct' seems to be th=
e way to get that object.
<br><br>My solution is primitive and I'll bet it could be optimized using t=
he CDBI internal API:<br>In 'Person' override the 'construct' method like t=
his:<br><br>sub construct {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m=
y $class =3D shift;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my $value=
_href =3D shift;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my $no_value_href =3D {map {=
$_ =3D&gt; ''} $class-&gt;columns};<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp; my $self =3D $class-&gt;SUPER::construct($no_value_href);<br><br>&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my %value_hash =3D %{$value_href} i=
f $value_href;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $self-&gt;set(=
%value_hash);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return $self;<br>}<br><br>No=
w, *all* the columns are initialized... Not just the ones sent values, and =
the program above will finish.<br><br>Any thoughts on this? Do I need to pu=
t this method in a base class that alll CDBI classes will inherit from or i=
s there any chance that this behavior can be integrated into CDBI-proper?
<br><br>Thank you for your time,<br>Daniel Fisher<br>

------=_Part_49870_7004149.1138295262461--


--===============1279769414==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

--===============1279769414==--

(message missing)

[CDBI] Deep recursion on subroutine "Class::DBI::_flesh"
Dan Fisher 17:07 on 26 Jan 2006

Re: [CDBI] Write out CDBI modules from Loader and Loader::Relationship
merlyn (Randal L. Schwartz) 03:17 on 27 Jan 2006

Re: [CDBI] Write out CDBI modules from Loader and Loader::Relationship
merlyn (Randal L. Schwartz) 18:01 on 27 Jan 2006

Generated at 11:37 on 31 Jan 2006 by mariachi v0.52