Re: Temporary databases / Closing the :memory: database connection
Oleg Broytman <[email protected]> Thu, 17 Oct 2013 21:46:08 +0400
| Newsgroups | gmane.comp.python.sqlobject |
|---|---|
| Message-ID | <[email protected]> |
Hi! On Wed, Oct 16, 2013 at 10:58:24PM +0100, "Maciej (Matchek) Blizi??ski" <[email protected]> wrote: > - there already is special handling for in-memory databases, so > maybe add a little more special handling for them; for example free > the memory on close(). The patch to test is attached. Oleg. -- Oleg Broytman http://phdru.name/ [email protected] Programmers don't die, they just GOSUB without RETURN. ------------------------------------------------------------------------------ October Webinars: Code for Performance Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk _______________________________________________ sqlobject-discuss mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
sqlite-memorydb.patch
(text/x-diff, 1.5 KB)
Index: sqlobject/sqlite/sqliteconnection.py
===================================================================
--- sqlobject/sqlite/sqliteconnection.py (revision 4673)
+++ sqlobject/sqlite/sqliteconnection.py (working copy)
@@ -89,11 +89,7 @@
self._threadPool = {}
self._threadOrigination = {}
if self._memory:
- self._memoryConn = sqlite.connect(
- self.filename, **self._connOptions)
- # Convert text data from SQLite to str, not unicode -
- # SQLObject converts it to unicode itself.
- self._memoryConn.text_factory = str
+ self.makeMemoryConnection()
@classmethod
def _connectionFromParams(cls, user, password, host, port, path, args):
@@ -184,6 +180,13 @@
return
conn.isolation_level = level
+ def makeMemoryConnection(self):
+ self._memoryConn = self.module.connect(
+ self.filename, **self._connOptions)
+ # Convert text data from SQLite to str, not unicode -
+ # SQLObject converts it to unicode itself.
+ self._memoryConn.text_factory = str
+
def makeConnection(self):
if self._memory:
return self._memoryConn
@@ -194,6 +197,9 @@
def close(self):
DBAPI.close(self)
self._threadPool = {}
+ if self._memory:
+ self._memoryConn.close()
+ self.makeMemoryConnection()
def _executeRetry(self, conn, cursor, query):
if self.debug: