added entity_quoting (False by default) parameter to DAL to optionally enable entity name quoting by adapters.
This commit is contained in:
+30
-11
@@ -675,15 +675,31 @@ class ConnectionPool(object):
|
||||
# metaclass to prepare adapter classes static values
|
||||
###################################################################################
|
||||
class AdapterMeta(type):
|
||||
def __new__(cls, clsname, bases, dct):
|
||||
classobj = super(AdapterMeta, cls).__new__(cls, clsname, bases, dct)
|
||||
classobj.REGEX_TABLE_DOT_FIELD = re.compile(r'^' + \
|
||||
classobj.QUOTE_TEMPLATE % REGEX_NO_GREEDY_ENTITY_NAME + \
|
||||
r'\.' + \
|
||||
classobj.QUOTE_TEMPLATE % REGEX_NO_GREEDY_ENTITY_NAME + \
|
||||
r'$')
|
||||
return classobj
|
||||
"""Metaclass to support manipulation of adapter classes.
|
||||
|
||||
At the moment is used to intercept entity_quoting argument passed to DAL.
|
||||
"""
|
||||
|
||||
def __call__(cls, *args, **kwargs):
|
||||
entity_quoting = kwargs.get('entity_quoting', False)
|
||||
if 'entity_quoting' in kwargs:
|
||||
del kwargs['entity_quoting']
|
||||
|
||||
obj = super(AdapterMeta, cls).__call__(*args, **kwargs)
|
||||
if not entity_quoting:
|
||||
quot = obj.QUOTE_TEMPLATE = '%s'
|
||||
regex_ent = r'(\w+)'
|
||||
else:
|
||||
quot = obj.QUOTE_TEMPLATE
|
||||
regex_ent = REGEX_NO_GREEDY_ENTITY_NAME
|
||||
obj.REGEX_TABLE_DOT_FIELD = re.compile(r'^' + \
|
||||
quot % regex_ent + \
|
||||
r'\.' + \
|
||||
quot % regex_ent + \
|
||||
r'$')
|
||||
|
||||
return obj
|
||||
|
||||
###################################################################################
|
||||
# this is a generic adapter that does nothing; all others are derived from this one
|
||||
###################################################################################
|
||||
@@ -7709,7 +7725,8 @@ class DAL(object):
|
||||
adapter_args=None, attempts=5, auto_import=False,
|
||||
bigint_id=False, debug=False, lazy_tables=False,
|
||||
db_uid=None, do_connect=True,
|
||||
after_connection=None, tables=None, ignore_field_case=True):
|
||||
after_connection=None, tables=None, ignore_field_case=True,
|
||||
entity_quoting=False):
|
||||
"""
|
||||
Creates a new Database Abstraction Layer instance.
|
||||
|
||||
@@ -7820,7 +7837,8 @@ class DAL(object):
|
||||
driver_args=driver_args or {},
|
||||
adapter_args=adapter_args or {},
|
||||
do_connect=do_connect,
|
||||
after_connection=after_connection)
|
||||
after_connection=after_connection,
|
||||
entity_quoting=entity_quoting)
|
||||
self._adapter = ADAPTERS[self._dbname](**kwargs)
|
||||
types = ADAPTERS[self._dbname].types
|
||||
# copy so multiple DAL() possible
|
||||
@@ -7847,7 +7865,8 @@ class DAL(object):
|
||||
else:
|
||||
self._adapter = BaseAdapter(db=self,pool_size=0,
|
||||
uri='None',folder=folder,
|
||||
db_codec=db_codec, after_connection=after_connection)
|
||||
db_codec=db_codec, after_connection=after_connection,
|
||||
entity_quoting=entity_quoting)
|
||||
migrate = fake_migrate = False
|
||||
adapter = self._adapter
|
||||
self._uri_hash = hashlib_md5(adapter.uri).hexdigest()
|
||||
|
||||
Reference in New Issue
Block a user