You are viewing a plain text version of this content. The canonical link for it is here.
Posted to asp@perl.apache.org by Patrick Conroy <pa...@gmail.com> on 2004/12/29 21:03:07 UTC

Cross-over between sessions

Hello all,

I am trying to see if I can make use of subs in global.asa to
consolidate redundant code across Apache::ASP pages, but I seem to be
getting cross-over between sessions.  My subs are of all set up like
this example:

sub history
{
        (my $histtype, my $dsc, my $contactid, my $usrid, my $dbh) = @_;

        my $sql_inserthistory = "insert into history (histtype, dsc,
contactid, crusr) values (?, ?, ?, ?)";

        my $sth = $dbh->prepare($sql_inserthistory) or die "Couldn't
prepare statement: " . $dbh->errstr;
        $sth->execute($histtype, $dsc, $contactid, $usrid) or die
"Couldn't execute statement: " . $sth->errstr;
}


But, I wind up getting a lot of history records from one user written
with the usrid of another user in a different session.  I assume that
whatever I am doing wrong is basic Perl or mod_perl stuff, rather than
specific to Apache::ASP, but I am hoping someone here can help me, or
at least point me in the right direction.  Any help would be greatly
appreciated.

Thanks,
Patrick

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: Cross-over between sessions

Posted by Josh Chamas <jo...@chamas.com>.
Patrick Conroy wrote:
>>You want
>>
>>        my ($histtype, $dsc, $contactid, $usrid, $dbh) = @_;
>>
>>here.
> 
> 
> Ok, I'll make this change.  Could the way I had this cause the
> variables to be shared across different calls to this sub?
> 

Seems possible, not sure what effect (my $this, my $that) = @_
would have and have never seen it done before.

 > ...
> Calls to this sub are made like so:
> history(1, "Test History", $Session->{contactid}, $Session->{usrid}, $dbh);
> 

This should work fine as long as the variables are scoped correctly,
you should not run into the my closure issues you have been experiencing.

Try also using UseStrict mode and see if it picks up any other problems.

Regards,

Josh

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: Cross-over between sessions

Posted by Patrick Conroy <pa...@gmail.com>.
> You want
> 
>         my ($histtype, $dsc, $contactid, $usrid, $dbh) = @_;
> 
> here.

Ok, I'll make this change.  Could the way I had this cause the
variables to be shared across different calls to this sub?

> >         my $sth = $dbh->prepare($sql_inserthistory) or die "Couldn't
> > prepare statement: " . $dbh->errstr;
> 
> For efficiency reasons, you should prepare that statement just once, and
> reuse it.  Possibly make it a global variable and init it in one of the
> OnStart event handlers.

I agree, but with the weird cross-over issue that I am having, I tried
to get rid of everything global until I figured this out.
 
> I don't see anywhere that you're using the $SessionID.

Calls to this sub are made like so:
history(1, "Test History", $Session->{contactid}, $Session->{usrid}, $dbh);

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: Cross-over between sessions

Posted by Warren Young <wa...@etr-usa.com>.
Patrick Conroy wrote:

>         (my $histtype, my $dsc, my $contactid, my $usrid, my $dbh) = @_;

You want

	my ($histtype, $dsc, $contactid, $usrid, $dbh) = @_;

here.

>         my $sth = $dbh->prepare($sql_inserthistory) or die "Couldn't
> prepare statement: " . $dbh->errstr;

For efficiency reasons, you should prepare that statement just once, and 
reuse it.  Possibly make it a global variable and init it in one of the 
OnStart event handlers.

> But, I wind up getting a lot of history records from one user written
> with the usrid of another user in a different session.

I don't see anywhere that you're using the $SessionID.

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org