本文整理汇总了Python中sqlalchemy.util.u函数的典型用法代码示例。如果您正苦于以下问题:Python u函数的具体用法?Python u怎么用?Python u使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了u函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: setup
def setup(self):
metadata.create_all()
t.insert().execute(
[
dict(
("field%d" % fnum, u("value%d" % fnum))
for fnum in range(NUM_FIELDS)
)
for r_num in range(NUM_RECORDS)
]
)
t2.insert().execute(
[
dict(
("field%d" % fnum, u("value%d" % fnum))
for fnum in range(NUM_FIELDS)
)
for r_num in range(NUM_RECORDS)
]
)
# warm up type caches
t.select().execute().fetchall()
t2.select().execute().fetchall()
testing.db.execute(
"SELECT %s FROM table1"
% (", ".join("field%d" % fnum for fnum in range(NUM_FIELDS)))
).fetchall()
testing.db.execute(
"SELECT %s FROM table2"
% (", ".join("field%d" % fnum for fnum in range(NUM_FIELDS)))
).fetchall()
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:32,代码来源:test_resultset.py
示例2: test_composed_multiple
def test_composed_multiple(self):
table = self.tables.some_table
lx = (table.c.x + table.c.y).label('lx')
ly = (func.lower(table.c.q) + table.c.p).label('ly')
self._assert_result(
select([lx, ly]).order_by(lx, ly.desc()),
[(3, util.u('q1p3')), (5, util.u('q2p2')), (7, util.u('q3p1'))]
)
开发者ID:cloudera,项目名称:hue,代码行数:8,代码来源:test_select.py
示例3: test_description_encoding
def test_description_encoding(self):
# amazingly, pysqlite seems to still deliver cursor.description
# as encoded bytes in py2k
t = Table("x", self.metadata, Column(u("méil"), Integer, primary_key=True), Column(ue("\u6e2c\u8a66"), Integer))
self.metadata.create_all(testing.db)
result = testing.db.execute(t.select())
assert u("méil") in result.keys()
assert ue("\u6e2c\u8a66") in result.keys()
开发者ID:niaolianyu,项目名称:sqlalchemy,代码行数:10,代码来源:test_sqlite.py
示例4: test_insert
def test_insert(self):
t1.insert().execute({u("méil"): 1, ue("\u6e2c\u8a66"): 5})
t2.insert().execute({u("a"): 1, u("b"): 1})
t3.insert().execute(
{ue("\u6e2c\u8a66_id"): 1, ue("unitable1_\u6e2c\u8a66"): 5, u("Unitéble2_b"): 1, ue("\u6e2c\u8a66_self"): 1}
)
assert t1.select().execute().fetchall() == [(1, 5)]
assert t2.select().execute().fetchall() == [(1, 1)]
assert t3.select().execute().fetchall() == [(1, 5, 1, 1)]
开发者ID:niaolianyu,项目名称:sqlalchemy,代码行数:10,代码来源:test_unicode.py
示例5: test_reflect
def test_reflect(self):
t1.insert().execute({u('méil'): 2, ue('\u6e2c\u8a66'): 7})
t2.insert().execute({u('a'): 2, u('b'): 2})
t3.insert().execute({ue('\u6e2c\u8a66_id'): 2,
ue('unitable1_\u6e2c\u8a66'): 7,
u('Unitéble2_b'): 2,
ue('\u6e2c\u8a66_self'): 2})
meta = MetaData(testing.db)
tt1 = Table(t1.name, meta, autoload=True)
tt2 = Table(t2.name, meta, autoload=True)
tt3 = Table(t3.name, meta, autoload=True)
tt1.insert().execute({u('méil'): 1, ue('\u6e2c\u8a66'): 5})
tt2.insert().execute({u('méil'): 1, ue('\u6e2c\u8a66'): 1})
tt3.insert().execute({ue('\u6e2c\u8a66_id'): 1,
ue('unitable1_\u6e2c\u8a66'): 5,
u('Unitéble2_b'): 1,
ue('\u6e2c\u8a66_self'): 1})
self.assert_(tt1.select(order_by=desc(u('méil'))).execute().fetchall() ==
[(2, 7), (1, 5)])
self.assert_(tt2.select(order_by=desc(u('méil'))).execute().fetchall() ==
[(2, 2), (1, 1)])
self.assert_(tt3.select(order_by=desc(ue('\u6e2c\u8a66_id'))).
execute().fetchall() ==
[(2, 7, 2, 2), (1, 5, 1, 1)])
开发者ID:Callek,项目名称:sqlalchemy,代码行数:27,代码来源:test_unicode.py
示例6: test_reflect
def test_reflect(self):
t1.insert().execute({u("méil"): 2, ue("\u6e2c\u8a66"): 7})
t2.insert().execute({u("a"): 2, u("b"): 2})
t3.insert().execute(
{ue("\u6e2c\u8a66_id"): 2, ue("unitable1_\u6e2c\u8a66"): 7, u("Unitéble2_b"): 2, ue("\u6e2c\u8a66_self"): 2}
)
meta = MetaData(unicode_bind)
tt1 = Table(t1.name, meta, autoload=True)
tt2 = Table(t2.name, meta, autoload=True)
tt3 = Table(t3.name, meta, autoload=True)
tt1.insert().execute({u("méil"): 1, ue("\u6e2c\u8a66"): 5})
tt2.insert().execute({u("méil"): 1, ue("\u6e2c\u8a66"): 1})
tt3.insert().execute(
{ue("\u6e2c\u8a66_id"): 1, ue("unitable1_\u6e2c\u8a66"): 5, u("Unitéble2_b"): 1, ue("\u6e2c\u8a66_self"): 1}
)
self.assert_(tt1.select(order_by=desc(u("méil"))).execute().fetchall() == [(2, 7), (1, 5)])
self.assert_(tt2.select(order_by=desc(u("méil"))).execute().fetchall() == [(2, 2), (1, 1)])
self.assert_(
tt3.select(order_by=desc(ue("\u6e2c\u8a66_id"))).execute().fetchall() == [(2, 7, 2, 2), (1, 5, 1, 1)]
)
meta.drop_all()
metadata.create_all()
开发者ID:niaolianyu,项目名称:sqlalchemy,代码行数:25,代码来源:test_unicode.py
示例7: test_wrap_unicode_arg
def test_wrap_unicode_arg(self):
# this is not supported by the API but oslo_db is doing it
orig = sa_exceptions.DBAPIError(False, False, False)
orig.args = [u('méil')]
eq_(
compat.text_type(orig),
compat.u(
"méil (Background on this error at: "
"http://sqlalche.me/e/dbapi)")
)
eq_(orig.args, (u('méil'),))
开发者ID:cpcloud,项目名称:sqlalchemy,代码行数:11,代码来源:test_except.py
示例8: test_insert
def test_insert(self):
t1.insert().execute({u('méil'):1, ue('\u6e2c\u8a66'):5})
t2.insert().execute({u('a'):1, u('b'):1})
t3.insert().execute({ue('\u6e2c\u8a66_id'): 1,
ue('unitable1_\u6e2c\u8a66'): 5,
u('Unitéble2_b'): 1,
ue('\u6e2c\u8a66_self'): 1})
assert t1.select().execute().fetchall() == [(1, 5)]
assert t2.select().execute().fetchall() == [(1, 1)]
assert t3.select().execute().fetchall() == [(1, 5, 1, 1)]
开发者ID:Callek,项目名称:sqlalchemy,代码行数:11,代码来源:test_unicode.py
示例9: test_create_drop_enum
def test_create_drop_enum(self):
# test escaping and unicode within CREATE TYPE for ENUM
typ = postgresql.ENUM("val1", "val2", "val's 3", u("méil"), name="myname")
self.assert_compile(
postgresql.CreateEnumType(typ), u("CREATE TYPE myname AS " "ENUM ('val1', 'val2', 'val''s 3', 'méil')")
)
typ = postgresql.ENUM("val1", "val2", "val's 3", name="PleaseQuoteMe")
self.assert_compile(
postgresql.CreateEnumType(typ), 'CREATE TYPE "PleaseQuoteMe" AS ENUM ' "('val1', 'val2', 'val''s 3')"
)
开发者ID:EvaSDK,项目名称:sqlalchemy,代码行数:11,代码来源:test_compiler.py
示例10: setup
def setup(self):
metadata.create_all()
t.insert().execute([dict(('field%d' % fnum, u('value%d' % fnum))
for fnum in range(NUM_FIELDS)) for r_num in
range(NUM_RECORDS)])
t2.insert().execute([dict(('field%d' % fnum, u('value%d' % fnum))
for fnum in range(NUM_FIELDS)) for r_num in
range(NUM_RECORDS)])
# warm up type caches
t.select().execute().fetchall()
t2.select().execute().fetchall()
开发者ID:CyberCollins,项目名称:sqlalchemy,代码行数:12,代码来源:test_resultset.py
示例11: test_col_targeting
def test_col_targeting(self):
t1.insert().execute({u("méil"): 1, ue("\u6e2c\u8a66"): 5})
t2.insert().execute({u("a"): 1, u("b"): 1})
t3.insert().execute(
{
ue("\u6e2c\u8a66_id"): 1,
ue("unitable1_\u6e2c\u8a66"): 5,
u("Unitéble2_b"): 1,
ue("\u6e2c\u8a66_self"): 1,
}
)
row = t1.select().execute().first()
eq_(row[t1.c[u("méil")]], 1)
eq_(row[t1.c[ue("\u6e2c\u8a66")]], 5)
row = t2.select().execute().first()
eq_(row[t2.c[u("a")]], 1)
eq_(row[t2.c[u("b")]], 1)
row = t3.select().execute().first()
eq_(row[t3.c[ue("\u6e2c\u8a66_id")]], 1)
eq_(row[t3.c[ue("unitable1_\u6e2c\u8a66")]], 5)
eq_(row[t3.c[u("Unitéble2_b")]], 1)
eq_(row[t3.c[ue("\u6e2c\u8a66_self")]], 1)
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:25,代码来源:test_unicode.py
示例12: test_quoted_column_non_unicode
def test_quoted_column_non_unicode(self):
metadata = self.metadata
table = Table(
"atable",
metadata,
Column("_underscorecolumn", Unicode(255), primary_key=True),
)
metadata.create_all()
table.insert().execute({"_underscorecolumn": u("’é")})
result = testing.db.execute(
table.select().where(table.c._underscorecolumn == u("’é"))
).scalar()
eq_(result, u("’é"))
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:14,代码来源:test_dialect.py
示例13: test_reflect_nvarchar
def test_reflect_nvarchar(self):
metadata = self.metadata
Table(
"tnv",
metadata,
Column("nv_data", sqltypes.NVARCHAR(255)),
Column("c_data", sqltypes.NCHAR(20)),
)
metadata.create_all()
m2 = MetaData(testing.db)
t2 = Table("tnv", m2, autoload=True)
assert isinstance(t2.c.nv_data.type, sqltypes.NVARCHAR)
assert isinstance(t2.c.c_data.type, sqltypes.NCHAR)
if testing.against("oracle+cx_oracle"):
assert isinstance(
t2.c.nv_data.type.dialect_impl(testing.db.dialect),
cx_oracle._OracleUnicodeStringNCHAR,
)
assert isinstance(
t2.c.c_data.type.dialect_impl(testing.db.dialect),
cx_oracle._OracleUnicodeStringNCHAR,
)
data = u("m’a réveillé.")
with testing.db.connect() as conn:
conn.execute(t2.insert(), dict(nv_data=data, c_data=data))
nv_data, c_data = conn.execute(t2.select()).first()
eq_(nv_data, data)
eq_(c_data, data + (" " * 7)) # char is space padded
assert isinstance(nv_data, util.text_type)
assert isinstance(c_data, util.text_type)
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:33,代码来源:test_types.py
示例14: test_unicodetext_nchar_mode
def test_unicodetext_nchar_mode(self):
self._test_setinputsizes(
UnicodeText(),
u("test"),
testing.db.dialect.dbapi.NCLOB,
set_nchar_flag=True,
)
开发者ID:vrajmohan,项目名称:sqlalchemy,代码行数:7,代码来源:test_types.py
示例15: test_unicode_nchar_mode
def test_unicode_nchar_mode(self):
self._test_setinputsizes(
Unicode(30),
u("test"),
testing.db.dialect.dbapi.NCHAR,
set_nchar_flag=True,
)
开发者ID:vrajmohan,项目名称:sqlalchemy,代码行数:7,代码来源:test_types.py
示例16: test_string_text_explicit_literal_binds
def test_string_text_explicit_literal_binds(self):
# the literal experssion here coerces the right side to
# Unicode on Python 3 for plain string, test with unicode
# string just to confirm literal is doing this
self.assert_compile(
column("x", String()) == literal(util.u("foo")),
"x = N'foo'",
literal_binds=True,
)
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:9,代码来源:test_types.py
示例17: setup_class
def setup_class(cls):
global metadata, t1, t2, t3
metadata = MetaData(testing.db)
t1 = Table(u('unitable1'), metadata,
Column(u('méil'), Integer, primary_key=True),
Column(ue('\u6e2c\u8a66'), Integer),
test_needs_fk=True,
)
t2 = Table(
u('Unitéble2'),
metadata,
Column(
u('méil'),
Integer,
primary_key=True,
key="a"),
Column(
ue('\u6e2c\u8a66'),
Integer,
ForeignKey(
u('unitable1.méil')),
key="b"),
test_needs_fk=True,
)
# Few DBs support Unicode foreign keys
if testing.against('sqlite'):
t3 = Table(ue('\u6e2c\u8a66'), metadata,
Column(ue('\u6e2c\u8a66_id'), Integer, primary_key=True,
autoincrement=False),
Column(ue('unitable1_\u6e2c\u8a66'), Integer,
ForeignKey(ue('unitable1.\u6e2c\u8a66'))
),
Column(u('Unitéble2_b'), Integer,
ForeignKey(u('Unitéble2.b'))
),
Column(ue('\u6e2c\u8a66_self'), Integer,
ForeignKey(ue('\u6e2c\u8a66.\u6e2c\u8a66_id'))
),
test_needs_fk=True,
)
else:
t3 = Table(ue('\u6e2c\u8a66'), metadata,
Column(ue('\u6e2c\u8a66_id'), Integer, primary_key=True,
autoincrement=False),
Column(ue('unitable1_\u6e2c\u8a66'), Integer),
Column(u('Unitéble2_b'), Integer),
Column(ue('\u6e2c\u8a66_self'), Integer),
test_needs_fk=True,
)
metadata.create_all()
开发者ID:Attsun1031,项目名称:sqlalchemy,代码行数:52,代码来源:test_unicode.py
示例18: test_no_convert_unicode
def test_no_convert_unicode(self):
"""test no utf-8 encoding occurs"""
dialect = sqlite.dialect()
for t in (
String(convert_unicode=True),
CHAR(convert_unicode=True),
Unicode(),
UnicodeText(),
String(convert_unicode=True),
CHAR(convert_unicode=True),
Unicode(),
UnicodeText(),
):
bindproc = t.dialect_impl(dialect).bind_processor(dialect)
assert not bindproc or isinstance(bindproc(util.u("some string")), util.text_type)
开发者ID:niaolianyu,项目名称:sqlalchemy,代码行数:16,代码来源:test_sqlite.py
示例19: setup_class
def setup_class(cls):
global unicode_bind, metadata, t1, t2, t3
unicode_bind = utf8_engine()
metadata = MetaData(unicode_bind)
t1 = Table(
u("unitable1"),
metadata,
Column(u("méil"), Integer, primary_key=True),
Column(ue("\u6e2c\u8a66"), Integer),
test_needs_fk=True,
)
t2 = Table(
u("Unitéble2"),
metadata,
Column(u("méil"), Integer, primary_key=True, key="a"),
Column(ue("\u6e2c\u8a66"), Integer, ForeignKey(u("unitable1.méil")), key="b"),
test_needs_fk=True,
)
# Few DBs support Unicode foreign keys
if testing.against("sqlite"):
t3 = Table(
ue("\u6e2c\u8a66"),
metadata,
Column(ue("\u6e2c\u8a66_id"), Integer, primary_key=True, autoincrement=False),
Column(ue("unitable1_\u6e2c\u8a66"), Integer, ForeignKey(ue("unitable1.\u6e2c\u8a66"))),
Column(u("Unitéble2_b"), Integer, ForeignKey(u("Unitéble2.b"))),
Column(ue("\u6e2c\u8a66_self"), Integer, ForeignKey(ue("\u6e2c\u8a66.\u6e2c\u8a66_id"))),
test_needs_fk=True,
)
else:
t3 = Table(
ue("\u6e2c\u8a66"),
metadata,
Column(ue("\u6e2c\u8a66_id"), Integer, primary_key=True, autoincrement=False),
Column(ue("unitable1_\u6e2c\u8a66"), Integer),
Column(u("Unitéble2_b"), Integer),
Column(ue("\u6e2c\u8a66_self"), Integer),
test_needs_fk=True,
)
metadata.create_all()
开发者ID:niaolianyu,项目名称:sqlalchemy,代码行数:43,代码来源:test_unicode.py
示例20: test_reflect_unicode_no_nvarchar
def test_reflect_unicode_no_nvarchar(self):
metadata = self.metadata
Table('tnv', metadata, Column('data', sqltypes.Unicode(255)))
metadata.create_all()
m2 = MetaData(testing.db)
t2 = Table('tnv', m2, autoload=True)
assert isinstance(t2.c.data.type, sqltypes.VARCHAR)
if testing.against('oracle+cx_oracle'):
assert isinstance(
t2.c.data.type.dialect_impl(testing.db.dialect),
cx_oracle._OracleString)
data = u('m’a réveillé.')
t2.insert().execute(data=data)
res = t2.select().execute().first()['data']
eq_(res, data)
assert isinstance(res, util.text_type)
开发者ID:m32,项目名称:sqlalchemy,代码行数:18,代码来源:test_types.py
注:本文中的sqlalchemy.util.u函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论