develooper Front page | perl.dbi.users | Postings from November 2011

Re: Design Pattern to keep a connection opened?

Thread Previous | Thread Next
From:
Bruce Johnson
Date:
November 5, 2011 20:46
Subject:
Re: Design Pattern to keep a connection opened?
Message ID:
5D67A327-3AB7-4488-93DD-53A0AB8447DB@pharmacy.arizona.edu

On Nov 5, 2011, at 3:57 PM, Brandon Phelps wrote:

> Can anyone point me in the right direction for keeping a connection to my database opened?
> 
> The script I need to write will run 24/7 executing a postgresql stored procedure which inserts records into the database.  The problem I think I might have is using a standard procedural syntax of:
> 
> Open connection
> Loop
>    Call stored procedure/function
> 
> ...if my connection gets interrupted somewhere during the loop any subsequent iterations will obviously fail, so I need a way of reconnecting to the database should the need arise.  Basically something like this (I'm just not sure how to actually code this):

Why not just open a database connection, run the procedure and close it again? :

Loop
	open db
	run proc
	close db
End loop

?
If the connection is staying open long enough to get stale and be disconnected, then you shouldn't be running into timing issues.



-- 
Bruce Johnson
University of Arizona
College of Pharmacy
Information Technology Group

Institutions do not have opinions, merely customs



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About