db access and base classes

Raaijmakers, Vincent (GE Infrastructure) Vincent.Raaijmakers at ge.com
Wed Jul 28 12:32:28 EDT 2004


[Greg Lindstrom]

| Hello-
| 
| I am writing an application that uses a base class to help 
| define multiple record segments. I would like to access a 
| SQL Server to generate job info, id numbers, etc. and would 
| like to place the connection in the base class so
| all segments use it via inheritance. My problem is I do not 
| know how to set things up so the connection is on opened once.


Create a module with a db class, containing a connect(), close() and all of your
methods (api) for accessing the database (your SQL's).
Make that class a singleton. Connect from your main application, or class. You can use now that api (containing the SQL's) directly from all of your modules without the need of a (re) connection. Even when you import that module in different other modules.

Works for me. Just a thought.

Vincent



More information about the Python-list mailing list