本文整理汇总了Python中sqlalchemy.sql.quoted_name方法的典型用法代码示例。如果您正苦于以下问题:Python sql.quoted_name方法的具体用法?Python sql.quoted_name怎么用?Python sql.quoted_name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.sql
的用法示例。
在下文中一共展示了sql.quoted_name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_quoted_name_label
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import quoted_name [as 别名]
def test_quoted_name_label(engine_testaccount):
test_cases = [
# quote name
{"label": quoted_name('alias', True),
"output": 'SELECT colname AS "alias" \nFROM abc GROUP BY colname'},
# not quote label
{"label": 'alias',
"output": 'SELECT colname AS alias \nFROM abc GROUP BY colname'},
# not quote mixed case label
{"label": 'Alias',
"output": 'SELECT colname AS "Alias" \nFROM abc GROUP BY colname'},
]
for t in test_cases:
col = column('colname').label(t["label"])
sel_from_tbl = select([col]).group_by(col).select_from(table('abc'))
compiled_result = sel_from_tbl.compile()
assert str(compiled_result) == t["output"]
示例2: __new__
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import quoted_name [as 别名]
def __new__(cls, value, quote):
if value is None:
return None
# experimental - don't bother with quoted_name
# if quote flag is None. doesn't seem to make any dent
# in performance however
# elif not sprcls and quote is None:
# return value
elif isinstance(value, cls) and (
quote is None or value.quote == quote
):
return value
self = super(quoted_name, cls).__new__(cls, value)
self.quote = quote
return self
示例3: test_schema_many_tokens_one
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import quoted_name [as 别名]
def test_schema_many_tokens_one(self):
metadata = MetaData()
tbl = Table(
"test",
metadata,
Column("id", Integer, primary_key=True),
schema="abc.def.efg.hij",
)
# for now, we don't really know what the above means, at least
# don't lose the dot
self.assert_compile(
select([tbl]),
"SELECT [abc.def.efg].hij.test.id FROM [abc.def.efg].hij.test",
)
dbname, owner = mssql_base._schema_elements("abc.def.efg.hij")
eq_(dbname, "abc.def.efg")
assert not isinstance(dbname, quoted_name)
eq_(owner, "hij")
示例4: make_label_compatible
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import quoted_name [as 别名]
def make_label_compatible(cls, label: str) -> Union[str, quoted_name]:
"""
Conditionally mutate and/or quote a sqlalchemy expression label. If
force_column_alias_quotes is set to True, return the label as a
sqlalchemy.sql.elements.quoted_name object to ensure that the select query
and query results have same case. Otherwise return the mutated label as a
regular string. If maxmimum supported column name length is exceeded,
generate a truncated label by calling truncate_label().
:param label: expected expression label/alias
:return: conditionally mutated label supported by the db engine
"""
label_mutated = cls._mutate_label(label)
if (
cls.max_column_name_length
and len(label_mutated) > cls.max_column_name_length
):
label_mutated = cls._truncate_label(label)
if cls.force_column_alias_quotes:
label_mutated = quoted_name(label_mutated, True)
return label_mutated
示例5: from_clause
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import quoted_name [as 别名]
def from_clause(self):
_from_clause = self._get_table_clause(self.fact_table)
for lookup in self.lookups:
_join_clause_and = []
for (idx, pk) in enumerate(lookup['join']['primary_key']):
fk = lookup['join']['foreign_key'][idx]
fk_table, fk_column = fk.split('.')
pk_table, pk_column = pk.split('.')
fk_table_quoted = sql.quoted_name(fk_table, True)
fk_column_quoted = sql.quoted_name(fk_column, True)
pk_table_quoted = sql.quoted_name(pk_table, True)
pk_column_quoted = sql.quoted_name(pk_column, True)
pk_column = sql.column(fk_column_quoted,
_selectable=sql.table(fk_table_quoted))
fk_column = sql.column(pk_column_quoted,
_selectable=sql.table(pk_table_quoted))
_join_clause_and.append(pk_column == fk_column)
_lookup = _Table(lookup.get('table'), lookup.get('alias'))
_is_left_join = lookup['join']['type'].lower() == 'left'
_from_clause = sql.join(
left=_from_clause,
right=self._get_table_clause(_lookup),
onclause=sql.and_(*_join_clause_and),
isouter=_is_left_join,
)
return _from_clause
示例6: _gen_label
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import quoted_name [as 别名]
def _gen_label(self, name):
t = self.table
if self.is_literal:
return None
elif t is not None and t.named_with_column:
if getattr(t, 'schema', None):
label = t.schema.replace('.', '_') + "_" + \
t.name + "_" + name
else:
label = t.name + "_" + name
# propagate name quoting rules for labels.
if getattr(name, "quote", None) is not None:
if isinstance(label, quoted_name):
label.quote = name.quote
else:
label = quoted_name(label, name.quote)
elif getattr(t.name, "quote", None) is not None:
# can't get this situation to occur, so let's
# assert false on it for now
assert not isinstance(label, quoted_name)
label = quoted_name(label, t.name.quote)
# ensure the label name doesn't conflict with that
# of an existing column
if label in t.c:
_label = label
counter = 1
while _label in t.c:
_label = label + "_" + str(counter)
counter += 1
label = _label
return _as_truncated(label)
else:
return name
示例7: __new__
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import quoted_name [as 别名]
def __new__(cls, value, quote):
if value is None:
return None
# experimental - don't bother with quoted_name
# if quote flag is None. doesn't seem to make any dent
# in performance however
# elif not sprcls and quote is None:
# return value
elif isinstance(value, cls) and (
quote is None or value.quote == quote
):
return value
self = super(quoted_name, cls).__new__(cls, value)
self.quote = quote
return self
示例8: __reduce__
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import quoted_name [as 别名]
def __reduce__(self):
return quoted_name, (util.text_type(self), self.quote)
示例9: __add__
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import quoted_name [as 别名]
def __add__(self, other):
return _anonymous_label(
quoted_name(
util.text_type.__add__(self, util.text_type(other)),
self.quote)
)
示例10: __radd__
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import quoted_name [as 别名]
def __radd__(self, other):
return _anonymous_label(
quoted_name(
util.text_type.__add__(util.text_type(other), self),
self.quote)
)
示例11: _make_proxy
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import quoted_name [as 别名]
def _make_proxy(
self,
selectable,
name=None,
name_is_truncatable=False,
disallow_is_literal=False,
**kw
):
# the "is_literal" flag normally should never be propagated; a proxied
# column is always a SQL identifier and never the actual expression
# being evaluated. however, there is a case where the "is_literal" flag
# might be used to allow the given identifier to have a fixed quoting
# pattern already, so maintain the flag for the proxy unless a
# :class:`.Label` object is creating the proxy. See [ticket:4730].
is_literal = (
not disallow_is_literal
and self.is_literal
and (
# note this does not accommodate for quoted_name differences
# right now
name is None
or name == self.name
)
)
c = self._constructor(
coercions.expect(roles.TruncatedLabelRole, name or self.name)
if name_is_truncatable
else (name or self.name),
type_=self.type,
_selectable=selectable,
is_literal=is_literal,
)
c._propagate_attrs = selectable._propagate_attrs
if name is None:
c.key = self.key
c._proxies = [self]
if selectable._is_clone_of is not None:
c._is_clone_of = selectable._is_clone_of.columns.get(c.key)
return c.key, c
示例12: __add__
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import quoted_name [as 别名]
def __add__(self, other):
return _anonymous_label(
quoted_name(
util.text_type.__add__(self, util.text_type(other)), self.quote
)
)
示例13: apply_map
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import quoted_name [as 别名]
def apply_map(self, map_):
if self.quote is not None:
# preserve quoting only if necessary
return quoted_name(self % map_, self.quote)
else:
# else skip the constructor call
return self % map_
示例14: test_force_schema_quoted_name_w_dot_case_insensitive
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import quoted_name [as 别名]
def test_force_schema_quoted_name_w_dot_case_insensitive(self):
metadata = MetaData()
tbl = Table(
"test",
metadata,
Column("id", Integer, primary_key=True),
schema=quoted_name("foo.dbo", True),
)
self.assert_compile(
select([tbl]), "SELECT [foo.dbo].test.id FROM [foo.dbo].test"
)
示例15: test_force_schema_quoted_w_dot_case_insensitive
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import quoted_name [as 别名]
def test_force_schema_quoted_w_dot_case_insensitive(self):
metadata = MetaData()
tbl = Table(
"test",
metadata,
Column("id", Integer, primary_key=True),
schema=quoted_name("foo.dbo", True),
)
self.assert_compile(
select([tbl]), "SELECT [foo.dbo].test.id FROM [foo.dbo].test"
)