Thanks Hardy. That's the method that I couldn't remember. (finish)
Ron -----Original Message----- From: Hardy Merrill [mailto:[EMAIL PROTECTED]] Sent: Monday, October 01, 2001 9:12 AM To: Ron Rohrssen Cc: Dbi-Users Subject: Re: Prepare/Exec statement reuse Although the perldocs(perldoc DBI) indicate that a finish is rarely required: (snippet) When all the data has been fetched from a SELECT statement, the driver should automatically call finish for you. So you should not normally need to call it explicitly. I normally "finish" statement handle before reusing it in a prepared select. See below. Ron Rohrssen [[EMAIL PROTECTED]] wrote: > When I prepare a statement and want to reuse it, do I need to release it in > some way? > > My program successfully prepares and executes on a database handle the first > time. But the second time I get "Invalid cursor state". > > Here's an example of the code: > > $stmtHandleOut = $dbh->prepare("select count(*) FROM table where datadate >= > ? and datadate <= ?"); > > sub mysub() > { > $stmtHandleOut->execute($StartTime, $EndTime); > > if (($nRecCount) = $stmtHandleOut->fetchrow_array) > { > return $nRecCount; ### I would remove the return, and instead assign ### $nRecCount to something like $result. $result = $nRecCount; > } > else > { > return 0; ### again, I'd remove the return... $result = 0; > } ### I'd add this $stmtHandleOut->finish; return $result; > } > > > Ron Rohrssen I, like you, didn't do any error checking of the dbi statements, so I'm assuming you set RaiseError on prior to this code, right? One more thing to check - make sure the statement handle is still in scope. HTH. -- Hardy Merrill Mission Critical Linux, Inc. http://www.missioncriticallinux.com
