Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def base_name(provider, name):
if not isinstance(name, basestring):
assert type(name) is tuple
name = name[-1]
assert isinstance(name, basestring)
return name
def parse_raw_sql(sql):
result = raw_sql_cache.get(sql)
if result is not None: return result
assert isinstance(sql, basestring) and len(sql) > 0
items = []
codes = []
pos = 0
while True:
try: i = sql.index('$', pos)
except ValueError:
items.append(sql[pos:])
break
items.append(sql[pos:i])
if sql[i+1] == '$':
items.append('$')
pos = i+2
else:
try: expr, _ = parse_expr(sql, i+1)
except ValueError:
raise ValueError(sql[i:])
uint64_support = True
dbapi_module = pyodbc
dbschema_cls = MSSchema
translator_cls = MSTranslator
sqlbuilder_cls = MSBuilder
default_schema_name = 'dbo'
name_before_table = 'db_name'
converter_classes = [
(NoneType, dbapiprovider.NoneConverter),
(bool, MSBoolConverter),
(basestring, MSStrConverter),
(int_types, MSIntConverter),
(float, MSRealConverter),
(Decimal, dbapiprovider.DecimalConverter),
(datetime, dbapiprovider.DatetimeConverter),
(date, MSDateConverter),
(time, MSTimeConverter),
(timedelta, MSTimedeltaConverter),
(UUID, MSUuidConverter),
(buffer, MSBlobConverter),
]
def normalize_name(provider, name):
return name[:provider.max_name_len].lower()
@wrap_dbapi_exceptions
def inspect_connection(provider, connection):
def pk_is_ready_to_define(entity, vdb):
if entity.bases:
for base in entity.bases:
base_name = base.name if not isinstance(base, basestring) else base
if base_name not in vdb.entities:
return False
return True
for pk_attr_name in entity.primary_key:
pk_attr = entity.attrs[pk_attr_name]
if pk_attr.reverse:
if pk_attr.py_type not in vdb.entities:
return False
return True
'WHERE ns.nspname = %s AND cls.relname = %s ' \
"AND con.contype = 'f' AND lower(con.conname) = lower(%s)"
cursor = connection.cursor()
cursor.execute(sql, [ schema_name, table_name, fk_name ])
row = cursor.fetchone()
return row[0] if row is not None else None
def drop_table(provider, connection, table_name):
cursor = connection.cursor()
sql = 'DROP TABLE %s CASCADE' % provider.quote_name(table_name)
cursor.execute(sql)
converter_classes = [
(NoneType, dbapiprovider.NoneConverter),
(bool, dbapiprovider.BoolConverter),
(basestring, PGStrConverter),
(int_types, PGIntConverter),
(float, PGRealConverter),
(Decimal, dbapiprovider.DecimalConverter),
(datetime, PGDatetimeConverter),
(date, dbapiprovider.DateConverter),
(time, dbapiprovider.TimeConverter),
(timedelta, PGTimedeltaConverter),
(UUID, PGUuidConverter),
(buffer, PGBlobConverter),
(ormtypes.Json, PGJsonConverter),
]
provider_cls = PGProvider
def flat(tree):
stack = [ tree ]
result = []
stack_pop = stack.pop
stack_extend = stack.extend
result_append = result.append
while stack:
x = stack_pop()
if isinstance(x, basestring): result_append(x)
else:
try: stack_extend(x)
except TypeError: result_append(x)
return result[::-1]
def force_text(s, encoding='utf-8', strings_only=False, errors='strict'):
"""
Similar to smart_text, except that lazy instances are resolved to
strings, rather than kept as lazy objects.
If strings_only is True, don't convert (some) non-string-like objects.
"""
# Handle the common case first for performance reasons.
if issubclass(type(s), unicode):
return s
if strings_only and is_protected_type(s):
return s
try:
if not issubclass(type(s), basestring):
if not PY2:
if isinstance(s, bytes):
s = unicode(s, encoding, errors)
else:
s = unicode(s)
elif hasattr(s, '__unicode__'):
s = unicode(s)
else:
s = unicode(bytes(s), encoding, errors)
else:
# Note: We use .decode() here, instead of unicode(s, encoding,
# errors), so that if s is a SafeBytes, it ends up being a
# SafeText at the end.
s = s.decode(encoding, errors)
except UnicodeDecodeError as e:
if isinstance(s, Exception):
def quote_name(provider, name):
quote_char = provider.quote_char
if isinstance(name, basestring):
name = name.replace(quote_char, quote_char+quote_char)
return quote_char + name + quote_char
return '.'.join(provider.quote_name(item) for item in name)
index_if_not_exists_syntax = False
max_time_precision = default_time_precision = 0
varchar_default_max_len = 255
uint64_support = True
dbapi_module = mysql_module
dbschema_cls = MySQLSchema
translator_cls = MySQLTranslator
sqlbuilder_cls = MySQLBuilder
fk_types = { 'SERIAL' : 'BIGINT UNSIGNED' }
converter_classes = [
(NoneType, dbapiprovider.NoneConverter),
(bool, dbapiprovider.BoolConverter),
(basestring, MySQLStrConverter),
(int_types, dbapiprovider.IntConverter),
(float, MySQLRealConverter),
(Decimal, dbapiprovider.DecimalConverter),
(datetime, dbapiprovider.DatetimeConverter),
(date, dbapiprovider.DateConverter),
(time, MySQLTimeConverter),
(timedelta, MySQLTimedeltaConverter),
(UUID, MySQLUuidConverter),
(buffer, MySQLBlobConverter),
(ormtypes.Json, MySQLJsonConverter),
]
def normalize_name(provider, name):
return name[:provider.max_name_len].lower()
@wrap_dbapi_exceptions