Database connections

Egbert Bouwman egbert.list at hccnet.nl
Thu Sep 23 11:35:18 CEST 2004


My aim is to develop a policy for database connections and commits,
however I do not fully understand these phenomena, and any comment is welcome.
I use postgres with psycopg.

The essence of my program is to do operations on a specific database,
so I need a connection all the time.
The program may run for hours or even days. Why not.

I can start a connection at the beginning of the program, and close it at
the end. 
Or I may do it as a class-level instruction in the class that is 
responsible for the database operations. So it is executed only once,
at the first import.

But it gives an insecure feeling. Connections may break down, and intruders
may misuse them.
I can test if the connection still exist before I do a real transaction.
How do I test, if not with some dummy execute ?

The alternative is to open and close a connection immediately before
and after each transaction + commit. Is that a too defensive way of life ?

egbert
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991
========================================================================



More information about the Python-list mailing list