views:

62

answers:

1

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 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?

+1  A: 

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?

ssokolow
Thanks and sorry for delay.
zefciu