From f11861d8e0154def291a179e03d1015c78264824 Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Mon, 4 Jul 2011 14:48:40 +0300 Subject: skytools.DBScript: drop connection if connect string has changed .reload() happens between .work() calls, so it's safe to drop connection on first .get_database() --- python/skytools/scripting.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'python') diff --git a/python/skytools/scripting.py b/python/skytools/scripting.py index a8baffd6..3d175429 100644 --- a/python/skytools/scripting.py +++ b/python/skytools/scripting.py @@ -659,10 +659,15 @@ class DBScript(BaseScript): """ max_age = self.cf.getint('connection_lifetime', DEF_CONN_AGE) + if not cache: cache = dbname if cache in self.db_cache: + if connstr is None: + connstr = self.cf.get(dbname, '') dbc = self.db_cache[cache] + if connstr: + dbc.check_connstr(connstr) else: if not connstr: connstr = self.cf.get(dbname) @@ -950,6 +955,12 @@ class DBCachedConn(object): conn.close() except: pass + def check_connstr(self, connstr): + """Drop connection if connect string has changed. + """ + if self.loc != connstr: + self.reset() + -- cgit v1.2.3