On Fri, Jan 03, 2003 at 05:01:53AM +0200, Boris Penchev wrote:
> Dear All,
>
> 1. Yes, I know that if you have prepare you can make a lot of execute of it, and
>that i can make this query in start of my program
> or in one module.
> 2. I think that is a good idea to declare $id and $name in while loop, because I use
>it only in this loop
> 3. I recommend you to use finish() method
I recommend you don't unless you know that the code will not read
all the rows that would be selected.
> 4 You can also use selectrow_array and all these things that do not need execute and
>finish, but is is again dangeraous, because if
> your sql query do not have rows --> it will display an error.
Please post some working code that demonstrates the problem.
> Sory for all time spending with read my emails.
It's important that the (many) misunderstandings about finish() are
cleared up.
Tim.
> Have a nice day.
>
> Best Regards,
> Boris Penchev
> ----- Original Message -----
> From: "Michael A Chase" <[EMAIL PROTECTED]>
> To: "dbi-users" <[EMAIL PROTECTED]>; "Boris Penchev" <[EMAIL PROTECTED]>
> Sent: Friday, January 03, 2003 4:29 AM
> Subject: Re: $sth->finish
>
>
> > On Fri, 3 Jan 2003 03:51:05 +0200 Boris Penchev <[EMAIL PROTECTED]> wrote:
> >
> > > Dear All,
> > >
> > > I has this fromlem when I have a lot of MySQL request. Now i do not have
> > > free time to explain this problem, but I give you smal
> > > example:
> > > my $sth = $dbh->prepare(qq~SELECT id, name FROM all~) || die
> > > "$DBI::errstr\n";
> > > $sth->execute();
> >
> > # You are not checking for errors from the execute() above.
> > # Prepare() $sth2 here, not inside the loop.
> > # Declare $id and $name before starting the while loop.
> >
> > > while ( my $id, $name = $sth->fetchrow_array() ) {
> >
> > # You need parenthesis around ($id, $name) to provide a list
> > # context for $sth->fetchrow_array().
> > # bind_columns() and fetch() would be more effecient.
> >
> > > my $sth2 = $dbh->prepare(qq~SELECT * FROM peopleaddress WHERE
> > > name = ?~) || die "$DBI::errstr\n";
> > > $sth2->execute($name);
> > > while (..............) {
> > > ....................
> > > }
> > > $sth2->finish();
> > > }
> > > $sth->finish();
> > >
> > > If you do not use finish() in these situation you might have big
> > > problems.
> >
> > It would be helpful if you could say what the big problems are.
> > If it's a memory leak, try moving the prepare outside the loop.
> >
> > You only need to prepare a statement once; you can then execute
> > it as many times as necessary without re-prepare()ing it.
> >
> > --
> > Mac :})
> > ** I normally forward private questions to the appropriate mail list. **
> > Ask Smarter: http://www.tuxedo.org/~esr/faqs/smart-questions.html
> > Give a hobbit a fish and he eats fish for a day.
> > Give a hobbit a ring and he eats fish for an age.
> >
>