]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
added workaround for funny pragma behavior on windows pysqlite
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 9 Jul 2006 17:58:01 +0000 (17:58 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 9 Jul 2006 17:58:01 +0000 (17:58 +0000)
singletonthreadpool has a dispose() method, used by proxy_engine test
to better clean up after itself on windows

lib/sqlalchemy/databases/sqlite.py
lib/sqlalchemy/pool.py
test/engine/proxy_engine.py

index b2aeb75fd590bf383fa90a499b97c7120f00cf5b..d96c0eda1a25d39985c1b9e0624f1adbd1504224 100644 (file)
@@ -154,6 +154,10 @@ class SQLiteDialect(ansisql.ANSIDialect):
     def has_table(self, connection, table_name):
         cursor = connection.execute("PRAGMA table_info(" + table_name + ")", {})
         row = cursor.fetchone()
+        
+        # consume remaining rows, to work around: http://www.sqlite.org/cvstrac/tktview?tn=1884
+        while cursor.fetchone() is not None:pass
+        
         return (row is not None)
 
     def reflecttable(self, connection, table):
index 9aa149d5ec11cb0b9f0dce39a9a7af7a9fe310fa..7a88ac6f7487f2f199a03005f4ec4bf40e9ab82e 100644 (file)
@@ -124,6 +124,12 @@ class Pool(object):
     def log(self, msg):
         self._logger.write(msg)
 
+    def dispose(self):
+        raise NotImplementedError()
+        
+    def __del__(self):
+        self.dispose()
+        
 class ConnectionFairy(object):
     def __init__(self, pool, connection=None):
         self.pool = pool
@@ -184,7 +190,14 @@ class SingletonThreadPool(Pool):
         self._creator = creator
 
     def dispose(self):
-        pass
+        for key, conn in self._conns.items():
+            try:
+                conn.close()
+            except:
+                # sqlite won't even let you close a conn from a thread that didn't create it
+                pass
+            del self._conns[key]
+            
     def status(self):
         return "SingletonThreadPool id:%d thread:%d size: %d" % (id(self), thread.get_ident(), len(self._conns))
 
@@ -241,8 +254,6 @@ class QueuePool(Pool):
                 conn.close()
             except Queue.Empty:
                 break
-    def __del__(self):
-        self.dispose()
 
     def status(self):
         tup = (self.size(), self.checkedin(), self.overflow(), self.checkedout())
index d468e946f2423d02a390c7dbfae0d0945a002c03..5b957b4dccf0dec07b23c0757287e176ec896759 100644 (file)
@@ -123,6 +123,7 @@ class ThreadProxyTest(ProxyTestBase):
                         assert names == [uname]
                     finally:
                         module_metadata.drop_all(module_engine)
+                        module_engine.get_engine().dispose()
                 except Exception, e:
                     import traceback
                     traceback.print_exc()
@@ -131,20 +132,18 @@ class ThreadProxyTest(ProxyTestBase):
                     queue.put(False)
             return test
 
-        # NOTE: I'm not sure how to give the test runner the option to
-        # override these uris, or how to safely clear them after test runs
         a = Thread(target=run('sqlite:///threadtesta.db', 'jim', qa))
         b = Thread(target=run('sqlite:///threadtestb.db', 'joe', qb))
         
         a.start()
         b.start()
-
+        
         # block and wait for the threads to push their results
-        res = qa.get(True)
+        res = qa.get()
         if res != False:
             raise res
 
-        res = qb.get(True)
+        res = qb.get()
         if res != False:
             raise res