[CDBI] Deep recursion on subroutine "Class::DBI::_flesh"
[prev]
[thread]
[next]
[Date index for 2006/01/26]
--===============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 "Class::DBI::_flesh" 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__->connection('dbi:mysql:test', 'test', '12345', {AutoCommit =3D> =
1, RaiseError =3D> 1, PrintError =3D> 1});
<br>__PACKAGE__->table('test_table');<br>__PACKAGE__->columns( Primar=
y =3D> qw/<br> id<br>/);<br>__=
PACKAGE__->columns( All =3D> qw/<br> &nb=
sp; id<br> name<br>/);<br><=
br>package main;<br><br>my $person_1 =3D Person->insert({});
<br>print $person_1->name."\n";<br>$person_1->delete();<br>=
<br>print '$person_1 created and deleted'."\n";<br><br>my $person=
_2 =3D Person->construct();<br>print $person_2->name."\n";
<br><br>print '$person_2 created and accessed'."\n";<br>print 'Pr=
ogram Completed'."\n";<br>---------------------------------------=
-------------------------------------------------------------------------
<br>
<br>When I run this, I get the following results:<br><br>$person_1 created =
and deleted<br>Deep recursion on subroutine "Class::DBI::_flesh" =
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> m=
y $class =3D shift;<br> my $value=
_href =3D shift;
<br> my $no_value_href =3D {map {=
$_ =3D> ''} $class->columns};<br> =
my $self =3D $class->SUPER::construct($no_value_href);<br><br>&nb=
sp; my %value_hash =3D %{$value_href} i=
f $value_href;<br> $self->set(=
%value_hash);
<br> 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
|