Re: Deep recusrion problem
[prev]
[thread]
[next]
[Date index for 2004/05/07]
Tony Bowden said on 5/7/2004 2:01 AM:
> On Fri, May 07, 2004 at 12:36:17AM -0400, Drew Taylor wrote:
>
>>I've run into a problem with deep recursion using CDBI 0.96 & latest
>>Ima::DBI. Nothing fancy - just your everyday cgi script. My apache has
>>mod_perl compiled in but the script is running under cgi-handler. I've
>>included some minimal code below that might help. Basically, I'm trying
>>to update a column value and getting hung. The part I don't understand
>>is that I'm using the same $model to successfully update the other
>>columns before the photo code below.
>
>
> I can't replicate this :(
>
> I'm using:
>
> ------
>
> package Foo::Model;
> use base 'Class::DBI::Test::SQLite';
> __PACKAGE__->set_table('profile');
> __PACKAGE__->columns(Primary=>'id');
> __PACKAGE__->columns(All=>qw(first last city state zip email year
> gender training_goal run_hours bike_hours swim_hours run_time bike_time
> swim_time note has_photo));
>
> __PACKAGE__->constrain_column(has_photo=>['0','1']);
>
> sub create_sql { q{
> id INTEGER PRIMARY KEY,
> first VARCHAR,
> last VARCHAR,
> city VARCHAR,
> state VARCHAR,
> zip VARCHAR,
> email VARCHAR,
> year VARCHAR,
> gender VARCHAR,
> training_goal VARCHAR,
> run_hours VARCHAR,
> bike_hours VARCHAR,
> swim_hours VARCHAR,
> run_time VARCHAR,
> bike_time VARCHAR,
> swim_time VARCHAR,
> note VARCHAR,
> has_photo VARCHAR
> }}
>
> package Foo::App;
>
> my $new = Foo::Model->create({ note => "Boo", has_photo => 0 });
> my $id = $new->id;
> undef $new;
>
> if ($id) {
> $model = Foo::Model->retrieve($id);
> print STDERR "Setting photo column\n";
> $model->has_photo('1');
> print STDERR "Commiting changes to database...\n";
> $model->update;
> print STDERR "DONE!\n";
> }
>
>
> ------
>
> Perhaps you could tweak that into something that fails?
>
> (Class::DBI::Test::SQLite, is available at
> http://www.tmtm.com/CPAN/SQLite.pm - it will be part of the distribution
> in the next version of Class::DBI)
>
> Tony
Well, I fixed it during my debugging this AM (although I'm not 100% sure
what did it). I added the following at one point and had the application
code call this instead of making the calls directly:
sub has_photo {
my $self = shift;
my $val = shift;
use Data::Dumper;
print STDERR "self [$self] val [$val]\n";
$self->photo('1');
$self->update;
}
At one point I saw "self [Foo::Model] val [1]" so I figured that somehow
the $model object was getting foobar'ed before the code I posted. Which
would make sense if this was being called as a class method rather than
an instance method. After juggling around some other things it works
great now! I think what was causing the problem was I was doing:
foreach my $col ($profile->columns('Essential')) {
$profile->$col($q->param($col));
}
And somewhere in there things got wacky. I changed the column group
names around and it's peachy again. Thanks for the encouragement.
Drew
--
---------------------------------------------------------
Drew Taylor * Web app development & consulting
drew@xxxxxxxxxx.xxx * Site implementation & hosting
www.drewtaylor.com * perl/mod_perl/DBI/mysql/postgres
---------------------------------------------------------