def __init__(self, pool, dbname, serialized=True): self.sql_from_log = {} self.sql_into_log = {} # default log level determined at cursor creation, could be # overridden later for debugging purposes self.sql_log = _logger.isEnabledFor(logging.DEBUG) self.sql_log_count = 0 self.__closed = True # avoid the call of close() (by __del__) if an exception # is raised by any of the following initialisations self._pool = pool self.dbname = dbname # Whether to enable snapshot isolation level for this cursor. # see also the docstring of Cursor. self._serialized = serialized self._cnx = pool.borrow(dsn(dbname)) self._obj = self._cnx.cursor(cursor_factory=psycopg1cursor) if self.sql_log: self.__caller = frame_codeinfo(currentframe(),2) else: self.__caller = False self.__closed = False # real initialisation value self.autocommit(False) self.__closer = False self._default_log_exceptions = True
def _close(self, leak=False): if not self._obj: return if self.sql_log: self.__closer = frame_codeinfo(currentframe(),3) self.print_log() self._obj.close() # This force the cursor to be freed, and thus, available again. It is # important because otherwise we can overload the server very easily # because of a cursor shortage (because cursors are not garbage # collected as fast as they should). The problem is probably due in # part because browse records keep a reference to the cursor. del self._obj self.__closed = True # Clean the underlying connection. self._cnx.rollback() if leak: self._cnx.leaked = True else: chosen_template = tools.config['db_template'] templates_list = tuple(set(['template0', 'template1', 'postgres', chosen_template])) keep_in_pool = self.dbname not in templates_list self._pool.give_back(self._cnx, keep_in_pool=keep_in_pool)
def __init__(self, pool, dbname, serialized=True): self.sql_from_log = {} self.sql_into_log = {} # default log level determined at cursor creation, could be # overridden later for debugging purposes self.sql_log = _logger.isEnabledFor(logging.DEBUG) self.sql_log_count = 0 self.__closed = True # avoid the call of close() (by __del__) if an exception # is raised by any of the following initialisations self._pool = pool self.dbname = dbname # Whether to enable snapshot isolation level for this cursor. # see also the docstring of Cursor. self._serialized = serialized self._cnx = pool.borrow(dsn(dbname)) self._obj = self._cnx.cursor(cursor_factory=psycopg1cursor) if self.sql_log: self.__caller = frame_codeinfo(currentframe(), 2) else: self.__caller = False self.__closed = False # real initialisation value self.autocommit(False) self.__closer = False self._default_log_exceptions = True self.cache = {}
def _close(self, leak=False): if not self._obj: return del self.cache if self.sql_log: self.__closer = frame_codeinfo(currentframe(), 3) self.print_log() self._obj.close() # This force the cursor to be freed, and thus, available again. It is # important because otherwise we can overload the server very easily # because of a cursor shortage (because cursors are not garbage # collected as fast as they should). The problem is probably due in # part because browse records keep a reference to the cursor. del self._obj self.__closed = True # Clean the underlying connection. self._cnx.rollback() if leak: self._cnx.leaked = True else: chosen_template = tools.config['db_template'] templates_list = tuple( set(['template0', 'template1', 'postgres', chosen_template])) keep_in_pool = self.dbname not in templates_list self._pool.give_back(self._cnx, keep_in_pool=keep_in_pool)
def __init__(self, name, value=None): if type(self) == except_orm: caller = frame_codeinfo(currentframe(), 1) _logger.warn('except_orm is deprecated. Please use specific exceptions like UserError or AccessError. Caller: %s:%s', *caller) self.name = name self.value = value self.args = (name, value)
def __init__(self, name, value=None): if type(self) == except_orm: caller = frame_codeinfo(currentframe(), 1) _logger.warn('except_orm is deprecated. Please use specific exceptions like UserError or AccessError. Caller: %s:%s', *caller) self.name = name self.value = value self.args = (name, value)
def _close(self, leak=False): global sql_counter if not self._obj: return del self.cache #funkring.net begin // remove all listeners if self.event_listener: self.execute("UNLISTEN *") del self.event_listener #funkring.net end if self.sql_log: self.__closer = frame_codeinfo(currentframe(), 3) # simple query count is always computed sql_counter += self.sql_log_count # advanced stats only if sql_log is enabled self.print_log() self._obj.close() # This force the cursor to be freed, and thus, available again. It is # important because otherwise we can overload the server very easily # because of a cursor shortage (because cursors are not garbage # collected as fast as they should). The problem is probably due in # part because browse records keep a reference to the cursor. del self._obj self._closed = True # Clean the underlying connection. self._cnx.rollback() if leak: self._cnx.leaked = True else: chosen_template = tools.config['db_template'] templates_list = tuple( set(['template0', 'template1', 'postgres', chosen_template])) keep_in_pool = self.dbname not in templates_list self.__pool.give_back(self._cnx, keep_in_pool=keep_in_pool)
def __init__(self, pool, dbname, serialized=False): self.sql_stats_log = {} # stats log will be a dictionary of # { (table, kind-of-qry): (num, delay, {queries?: num}) } # default log level determined at cursor creation, could be # overridden later for debugging purposes self.sql_log = self.__logger.isEnabledFor(logging.DEBUG_SQL) self.sql_log_count = 0 self.__closed = True # avoid the call of close() (by __del__) if an exception # is raised by any of the following initialisations self._pool = pool self.dbname = dbname self.auth_proxy = None self._serialized = serialized self._cnx, self._obj = pool.borrow(dsn(dbname), True) self.__closed = False # real initialisation value self.autocommit(False) if self.sql_log: self.__caller = frame_codeinfo(currentframe(),2) else: self.__caller = False if not hasattr(self._cnx,'_prepared'): self._cnx._prepared = [] if not self.__pgmode: # No features shall use these modes yet! #if self._cnx.server_version >= 90200: # self.__pgmode = 'pg92' #elif self._cnx.server_version >= 90100: # self.__pgmode = 'pg91' if self._cnx.server_version >= 90000: self.__pgmode = 'pg90' elif self._cnx.server_version >= 80400: self.__pgmode = 'pg84' else: self.__pgmode = 'pgsql'
def __init__(self, pool, dbname, dsn, serialized=True): self.sql_from_log = {} self.sql_into_log = {} # default log level determined at cursor creation, could be # overridden later for debugging purposes self.sql_log = _logger.isEnabledFor(logging.DEBUG) self.sql_log_count = 0 # avoid the call of close() (by __del__) if an exception # is raised by any of the following initialisations self._closed = True self.__pool = pool self.dbname = dbname # Whether to enable snapshot isolation level for this cursor. # see also the docstring of Cursor. self._serialized = serialized self._cnx = pool.borrow(dsn) self._obj = self._cnx.cursor() if self.sql_log: self.__caller = frame_codeinfo(currentframe(), 2) else: self.__caller = False self._closed = False # real initialisation value self.autocommit(False) self.__closer = False self._default_log_exceptions = True self.cache = {} self._files_to_clean = [] # event handlers, see method after() below self._event_handlers = {'commit': [], 'rollback': []}