[Tutor] Opening and closing SQLite db
smokefloat at gmail.com
Sun Dec 26 17:27:12 CET 2010
On Sun, Dec 26, 2010 at 11:16 AM, Noah Hall <enalicho at gmail.com> wrote:
> As a rule, I tend to open and close a connection based on what I'm doing
> with the database.
I +1 that. Usually if I open the db in a function, I commit and close.
If it's in an app, for me personally, that should be the only place it
takes place. So insert into, or call from would seem more likely
functions to retrieve in a certain situation, like opening a project
file would open the project db file, load the info, and then
commit/close. Then saving would open commit/close the required info.
If I were to directly run a series of queries one after
> another, I would keep it open until a change in interface (referring to
> changes in objects, both masters and slaves).
> Also, you can perform any query that does not change any records safely
> without a commit, for example, searches. For everything else, you need to
> call commit - but you don't need to close the connection.
Nor open one, if it's not necessary. Load the info on file open, do
what the user does, then save through open close. Unless intermittent
saves are necessary within the app loop.
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
They're installing the breathalyzer on my email account next week.
More information about the Tutor