本文整理匯總了Python中sqlalchemy.util.u方法的典型用法代碼示例。如果您正苦於以下問題:Python util.u方法的具體用法?Python util.u怎麽用?Python util.u使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sqlalchemy.util
的用法示例。
在下文中一共展示了util.u方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_insert
# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import u [as 別名]
def test_insert(self, connection):
connection.execute(t1.insert(), {u("méil"): 1, ue("\u6e2c\u8a66"): 5})
connection.execute(t2.insert(), {u("a"): 1, u("b"): 1})
connection.execute(
t3.insert(),
{
ue("\u6e2c\u8a66_id"): 1,
ue("unitable1_\u6e2c\u8a66"): 5,
u("Unitéble2_b"): 1,
ue("\u6e2c\u8a66_self"): 1,
},
)
eq_(connection.execute(t1.select()).fetchall(), [(1, 5)])
eq_(connection.execute(t2.select()).fetchall(), [(1, 1)])
eq_(connection.execute(t3.select()).fetchall(), [(1, 5, 1, 1)])
示例2: test_exception_wrapping_non_dbapi_statement
# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import u [as 別名]
def test_exception_wrapping_non_dbapi_statement(self):
class MyType(TypeDecorator):
impl = Integer
def process_bind_param(self, value, dialect):
raise SomeException("nope")
def _go(conn):
assert_raises_message(
tsa.exc.StatementError,
r"\(.*.SomeException\) " r"nope\n\[SQL\: u?SELECT 1 ",
conn.execute,
select([1]).where(column("foo") == literal("bar", MyType())),
)
_go(testing.db)
with testing.db.connect() as conn:
_go(conn)
示例3: test_stmt_exception_bytestring_raised
# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import u [as 別名]
def test_stmt_exception_bytestring_raised(self):
name = util.u("méil")
with testing.db.connect() as conn:
assert_raises_message(
tsa.exc.StatementError,
util.u(
"A value is required for bind parameter 'uname'\n"
r".*SELECT users.user_name AS .m\xe9il."
)
if util.py2k
else util.u(
"A value is required for bind parameter 'uname'\n"
".*SELECT users.user_name AS .méil."
),
conn.execute,
select([users.c.user_name.label(name)]).where(
users.c.user_name == bindparam("uname")
),
{"uname_incorrect": "foo"},
)
示例4: test_reflect_unicode_no_nvarchar
# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import u [as 別名]
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)
示例5: test_unicode_round_trip
# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import u [as 別名]
def test_unicode_round_trip(self, connection):
s = select(
[
cast(
{
util.u("réveillé"): util.u("réveillé"),
"data": {"k1": util.u("drôle")},
},
self.test_type,
)
]
)
eq_(
connection.scalar(s),
{
util.u("réveillé"): util.u("réveillé"),
"data": {"k1": util.u("drôle")},
},
)
示例6: define_tables
# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import u [as 別名]
def define_tables(cls, metadata):
Table(
"data",
metadata,
Column("id", Integer, primary_key=True),
Column("x", String),
Column("y", String),
Column("z", Integer, server_default="5"),
)
Table(
u("Unitéble2"),
metadata,
Column(u("méil"), Integer, primary_key=True),
Column(ue("\u6e2c\u8a66"), Integer),
)
示例7: test_create_drop_enum
# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import u [as 別名]
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')",
)
示例8: test_charset_collate_table
# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import u [as 別名]
def test_charset_collate_table(self):
t = Table(
"foo",
self.metadata,
Column("id", Integer),
Column("data", UnicodeText),
mysql_default_charset="utf8",
mysql_collate="utf8_bin",
)
t.create()
m2 = MetaData(testing.db)
t2 = Table("foo", m2, autoload=True)
eq_(t2.kwargs["mysql_collate"], "utf8_bin")
eq_(t2.kwargs["mysql_default charset"], "utf8")
# test [ticket:2906]
# in order to test the condition here, need to use
# MySQLdb 1.2.3 and also need to pass either use_unicode=1
# or charset=utf8 to the URL.
t.insert().execute(id=1, data=u("some text"))
assert isinstance(
testing.db.scalar(select([t.c.data])), util.text_type
)
示例9: test_unicode_roundtrip
# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import u [as 別名]
def test_unicode_roundtrip(self):
set_table = Table(
"t",
self.metadata,
Column("id", Integer, primary_key=True),
Column("data", mysql.SET(u("réveillé"), u("drôle"), u("S’il"))),
)
set_table.create()
with testing.db.begin() as conn:
conn.execute(
set_table.insert(), {"data": set([u("réveillé"), u("drôle")])}
)
row = conn.execute(set_table.select()).first()
eq_(row, (1, set([u("réveillé"), u("drôle")])))
示例10: _bug_88718_96365_casing_1
# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import u [as 別名]
def _bug_88718_96365_casing_1(self):
fkeys_casing_1 = [
{
"name": "FK_PlaylistTTrackId",
"constrained_columns": ["TTrackID"],
"referred_schema": "Test_Schema",
"referred_table": "Track",
"referred_columns": ["trackid"],
"options": {},
},
{
"name": "FK_PlaylistTrackId",
"constrained_columns": ["TrackID"],
"referred_schema": None,
"referred_table": "Track",
"referred_columns": ["trackid"],
"options": {},
},
]
ischema_casing_1 = [
(util.u("Test"), util.u("Track"), "TrackID"),
(util.u("Test_Schema"), util.u("Track"), "TrackID"),
]
return fkeys_casing_1, ischema_casing_1
示例11: define_tables
# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import u [as 別名]
def define_tables(cls, metadata):
Table(
"q",
metadata,
Column("x", Integer, default=2),
Column("y", Integer, onupdate=5),
Column("z", Integer),
)
Table(
"p",
metadata,
Column("s", Integer),
Column("t", Integer),
Column("u", Integer, onupdate=1),
)
示例12: test_list_assignment_new
# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import u [as 別名]
def test_list_assignment_new(self):
User, Order = self.classes.User, self.classes.Order
sess = Session()
u = User(
name="jack",
orders=[
Order(description="order 1"),
Order(description="order 2"),
],
)
sess.add(u)
sess.commit()
eq_(
u,
User(
name="jack",
orders=[
Order(description="order 1"),
Order(description="order 2"),
],
),
)
示例13: test_remove_pending_from_pending_parent
# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import u [as 別名]
def test_remove_pending_from_pending_parent(self):
# test issue #4040
User, Order = self.classes.User, self.classes.Order
sess = Session()
u = User(name="jack")
o1 = Order()
sess.add(o1)
# object becomes an orphan, but parent is not in session
u.orders.append(o1)
u.orders.remove(o1)
sess.add(u)
assert o1 in sess
sess.flush()
assert o1 not in sess
示例14: test_delete
# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import u [as 別名]
def test_delete(self):
User, users, orders, Order = (
self.classes.User,
self.tables.users,
self.tables.orders,
self.classes.Order,
)
sess = create_session()
u = User(
name="jack",
orders=[
Order(description="someorder"),
Order(description="someotherorder"),
],
)
sess.add(u)
sess.flush()
sess.delete(u)
sess.flush()
eq_(select([func.count("*")]).select_from(users).scalar(), 0)
eq_(select([func.count("*")]).select_from(orders).scalar(), 0)
示例15: test_column_prefix
# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import u [as 別名]
def test_column_prefix(self):
users, User = self.tables.users, self.classes.User
mapper(
User,
users,
column_prefix="_",
properties={"user_name": synonym("_name")},
)
s = create_session()
u = s.query(User).get(7)
eq_(u._name, "jack")
eq_(u._id, 7)
u2 = s.query(User).filter_by(user_name="jack").one()
assert u is u2