[Tutor] How should my code handle db connections? Should my db manager module use OOP?

boB Stepp robertvstepp at gmail.com
Thu Aug 27 02:11:42 CEST 2015

My ongoing project will be centered around an SQLite db.  Since almost
all data needed by the program will be stored in this db, my thought
is that I should create a connection to this db shortly after program
startup and keep this connection open until program closure.  I am
assuming that opening and closing a db connection has enough overhead
that I should only do this once.  But I do not *know* that this is
true.  Is it?  If not, then the alternative would make more sense,
i.e., open and close the db as needed.

In the first iteration of my project, my intent is to create and
populate the db with tables external to the program.  The program will
only add entries to tables, query the db, etc.  That is, the structure
of the db will be pre-set outside of the program, and the program will
only deal with data interactions with the db.  My intent is to make
the overall design of the program OO, but I am wondering how to handle
the db manager module.  Should I go OO here as well?  With each
pertinent method handling a very specific means of interacting with
the db?  Or go a procedural route with functions similar to the
aforementioned methods?  It is not clear to me that OOP provides a
real benefit here, but, then again, I am learning how to OOP during
this project as well, so I don't have enough knowledge yet to
realistically answer this question.


More information about the Tutor mailing list