Oracle的奇怪SQLAlchemy bindparam行为,字符串转换为二进制

时间:2016-04-14 17:52:51

标签: python oracle sqlalchemy

示例代码:

from sqlalchemy import Table, Column, Unicode, MetaData, create_engine, select

metadata = MetaData()

mytable = Table(
    "mytable",
    metadata,
    Column("foo", Unicode(14)),
)

engine = create_engine("oracle://...", encoding="iso-8859-9", echo=True)
stmt = select([mytable]).where(mytable.c.foo == "bar")
engine.execute(stmt)

现在,如果我执行代码并查看SQLAlchemy日志,我会看到以下内容:

INFO sqlalchemy.engine.base.Engine SELECT mytable.foo FROM mytable WHERE mytable.foo = :foo_1 
INFO sqlalchemy.engine.base.Engine {'foo_1': b'bar'}

出于某种原因,SQLAlchemy将用作where子句一部分的字符串编码为二进制字符串。为什么会这样?我做错了什么?

0 个答案:

没有答案