Esempio n. 1
0
 def __init__(self, driver, cnx=None, encoding='UTF-8'):
     """cnx : optional Python DB API 2.0 connexion"""
     self.driver = driver
     self._cnx = cnx
     self.encoding = encoding
     self.dbhelper = get_adv_func_helper(driver)
Esempio n. 2
0
 def setUp(self):
     self.helper = get_adv_func_helper(self.driver)
Esempio n. 3
0
    except ValueError:
        raise UnknownDriver('Unknown module %s for %s' % (module, database))
    modules.insert(0, module)

def get_dbapi_compliant_module(driver, prefered_drivers = None, quiet = False,
                               pywrap = False):
    """returns a fully dbapi compliant module"""
    try:
        mod = ADAPTER_DIRECTORY.adapt(driver, prefered_drivers, pywrap=pywrap)
    except NoAdapterFound, err:
        if not quiet:
            msg = 'No Adapter found for %s, returning native module'
            print >> sys.stderr, msg % err.objname
        mod = err.adapted_obj
    from logilab.common.adbh import get_adv_func_helper
    mod.adv_func_helper = get_adv_func_helper(driver)
    return mod

def get_connection(driver='postgres', host='', database='', user='',
                  password='', port='', quiet=False, drivers=PREFERED_DRIVERS,
                  pywrap=False, extra_args=None):
    """return a db connection according to given arguments"""
    module, modname = _import_driver_module(driver, drivers, ['connect'])
    try:
        adapter = ADAPTER_DIRECTORY.get_adapter(driver, modname)
    except NoAdapterFound, err:
        if not quiet:
            msg = 'No Adapter found for %s, using default one' % err.objname
            print >> sys.stderr, msg
        adapted_module = DBAPIAdapter(module, pywrap)
    else: