开发者

Utf-8 with sqlalchemy on a database with init connect

I am trying to use sqlalchemy to connect with mysql database. I have set up charset=utf-8$use_unicode=0. This worked with almost all databases, but not with a particular one. I believe it is because it has 'init-connect' variable set to 'SET NAMES latin2;' I have no privileges to change that.

It works for me if I send explicit query SET NAMES utf8, however if there is a temporal disconnection, then after开发者_Python百科 reconnecting my program breaks again as it gets lati2-encoded data from the server.

Is it possible to create some hook to always send the SET NAMES when sqlalchemy connects? Or any other way to solve this problem?


Sounds like what you want is a custom PoolListener. This SO answer explains how to write one in the context of SQLite's PRAGMA foreign_keys=ON

Sqlite / SQLAlchemy: how to enforce Foreign Keys?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜