From 6e5bc03082b923741f332d7c5f0e011f5f0f4bb2 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Sat, 17 Jul 2010 20:16:42 +0200 Subject: [PATCH] [entropy.db] add temporary argument to _doesTableExist() to check against temp tables --- libraries/entropy/db/__init__.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/libraries/entropy/db/__init__.py b/libraries/entropy/db/__init__.py index 0405070ac..1dc0f6bb1 100644 --- a/libraries/entropy/db/__init__.py +++ b/libraries/entropy/db/__init__.py @@ -4533,16 +4533,27 @@ class EntropyRepository(EntropyRepositoryBase): """) return self._cur2list(cur) - def _doesTableExist(self, table): + def _doesTableExist(self, table, temporary = False): - # speed up a bit if we already reported a column as existing + # NOTE: override cache when temporary is True + if temporary: + # temporary table do not pop-up with the statement below, so + # we need to handle them with "care" + try: + self._cursor().execute(""" + SELECT count(*) FROM (?) LIMIT 1""", (table,)) + except OperationalError: + return False + return True + + # speed up a bit if we already reported a table as existing c_tup = ("_doesTableExist", table,) cached = self.__live_cache.get(c_tup) if cached is not None: return cached cur = self._cursor().execute(""" - select name from SQLITE_MASTER where type = "table" and name = (?) + SELECT name FROM SQLITE_MASTER WHERE type = "table" AND name = (?) LIMIT 1 """, (table,)) rslt = cur.fetchone()