__all__ = ['db_connect', 'close_db']
-from threading import current_thread
+from threading import currentThread
import logging
from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT, ISOLATION_LEVEL_READ_COMMITTED, ISOLATION_LEVEL_SERIALIZABLE
from psycopg2.psycopg1 import cursor as psycopg1cursor
self.__logger.warn(query)
self.__logger.warn("SQL queries cannot contain %d or %f anymore. "
"Use only %s")
- if params:
- query = query.replace('%d', '%s').replace('%f', '%s')
if self.sql_log:
now = mdt.now()
sqllogitems = sqllogs[type].items()
sqllogitems.sort(key=lambda k: k[1][1])
self.__logger.log(logging.DEBUG_SQL, "SQL LOG %s:", type)
+ sqllogitems.sort(lambda x,y: cmp(x[1][0], y[1][0]))
for r in sqllogitems:
delay = timedelta(microseconds=r[1][1])
self.__logger.log(logging.DEBUG_SQL, "table: %s: %s/%s",
_Pool = ConnectionPool(int(tools.config['db_maxconn']))
def db_connect(db_name):
- current_thread().dbname = db_name
+ currentThread().dbname = db_name
return Connection(_Pool, db_name)
def close_db(db_name):
_Pool.close_all(dsn(db_name))
tools.cache.clean_caches_for_db(db_name)
- ct = current_thread()
+ ct = currentThread()
if hasattr(ct, 'dbname'):
delattr(ct, 'dbname')