are there pros or contras, keeping a connection to a (sqlite) database ?
gh at ghaering.de
Fri Sep 10 00:16:58 CEST 2010
On Thu, Sep 9, 2010 at 12:29 AM, CM <cmpython at gmail.com> wrote:
> I'm not even sure what a "connection" really is; I assumed it was
> nothing more than a rule that says to write to the database with the
> file named in the parentheses. [...]
The following list is not exclusive, but these are the first things
that I can think of.
- SQLite connections have state like uncommitted transactions
- SQLite connections have page caches and metadata caches (tables,
structures and indices)
Opening and closing SQLite connections is very cheap, but keeping
connections open is usually a better approach. You have to have a
"global" setting like the path to the database file anyway; so you can
wrap a "global" connection object in a factory function just as well.
In database applications that use the raw DB-APi i usually start with
# return database connection
More information about the Python-list