equal
deleted
inserted
replaced
297 """Mixin for SQL data sources, getting a connection from a configuration |
297 """Mixin for SQL data sources, getting a connection from a configuration |
298 dictionary and handling connection locking |
298 dictionary and handling connection locking |
299 """ |
299 """ |
300 cnx_wrap = ConnectionWrapper |
300 cnx_wrap = ConnectionWrapper |
301 |
301 |
302 def __init__(self, source_config): |
302 def __init__(self, source_config, repairing=False): |
303 try: |
303 try: |
304 self.dbdriver = source_config['db-driver'].lower() |
304 self.dbdriver = source_config['db-driver'].lower() |
305 dbname = source_config['db-name'] |
305 dbname = source_config['db-name'] |
306 except KeyError: |
306 except KeyError: |
307 raise ConfigurationError('missing some expected entries in sources file') |
307 raise ConfigurationError('missing some expected entries in sources file') |
326 self._process_value = dbapi_module.process_value |
326 self._process_value = dbapi_module.process_value |
327 self._dbencoding = dbencoding |
327 self._dbencoding = dbencoding |
328 if self.dbdriver == 'sqlite': |
328 if self.dbdriver == 'sqlite': |
329 self.cnx_wrap = SqliteConnectionWrapper |
329 self.cnx_wrap = SqliteConnectionWrapper |
330 self.dbhelper.dbname = abspath(self.dbhelper.dbname) |
330 self.dbhelper.dbname = abspath(self.dbhelper.dbname) |
|
331 if not repairing: |
|
332 statement_timeout = int(source_config.get('db-statement-timeout', 0)) |
|
333 if statement_timeout > 0: |
|
334 def set_postgres_timeout(cnx): |
|
335 cnx.cursor().execute('SET statement_timeout to %d' % statement_timeout) |
|
336 cnx.commit() |
|
337 postgres_hooks = SQL_CONNECT_HOOKS['postgres'] |
|
338 postgres_hooks.append(set_postgres_timeout) |
331 |
339 |
332 def wrapped_connection(self): |
340 def wrapped_connection(self): |
333 """open and return a connection to the database, wrapped into a class |
341 """open and return a connection to the database, wrapped into a class |
334 handling reconnection and all |
342 handling reconnection and all |
335 """ |
343 """ |