diff options
author | Sylvain <syt@logilab.fr> | 2008-02-21 13:54:04 +0100 |
---|---|---|
committer | Sylvain <syt@logilab.fr> | 2008-02-21 13:54:04 +0100 |
commit | 8c6042e6999c0bdb683c1d7b030dd65ba8654a83 (patch) | |
tree | 48867c0292deaa1b9279a76d5f53ebd208d61e35 /db.py | |
parent | 5e298af2440418eacb5615e663aa295ae4a7b9a3 (diff) | |
download | logilab-common-8c6042e6999c0bdb683c1d7b030dd65ba8654a83.tar.gz |
* adbh: mysql doesn't support ILIKE, implement list_indices for mysql
* db: mysql adapter use mx DateTime when available, fix unicode handling
Diffstat (limited to 'db.py')
-rw-r--r-- | db.py | 28 |
1 files changed, 27 insertions, 1 deletions
@@ -425,8 +425,30 @@ class _MySqlDBAdapter(DBAPIAdapter): """Simple mysql Adapter to DBAPI """ BOOLEAN = 'XXX' # no specific type code for boolean + + def __init__(self, native_module, pywrap=False): + DBAPIAdapter.__init__(self, native_module, pywrap) + self._init_module() + + def _init_module(self): + """initialize mysqldb to use mx.DateTime for date and timestamps""" + natmod = self._native_module + if hasattr(natmod, '_lc_initialized'): + return + natmod._lc_initialized = 1 + # date/time types handling + if HAS_MX_DATETIME: + from MySQLdb import times + from mx import DateTime as mxdt + times.Date = times.date = mxdt.Date + times.Time = times.time = mxdt.Time + times.Timestamp = times.datetime = mxdt.DateTime + times.TimeDelta = times.timedelta = mxdt.TimeDelta + times.DateTimeType = mxdt.DateTimeType + times.DateTimeDeltaType = mxdt.DateTimeDeltaType + def connect(self, host='', database='', user='', password='', port=None, - unicode=True): + unicode=True, charset='utf8'): """Handles mysqldb connexion format the unicode named argument asks to use Unicode objects for strings in result sets and query parameters @@ -438,6 +460,10 @@ class _MySqlDBAdapter(DBAPIAdapter): if port: kwargs['port'] = int(port) cnx = self._native_module.connect(**kwargs) + if unicode: + if charset.lower() == 'utf-8': + charset = 'utf8' + cnx.set_character_set(charset) return self._wrap_if_needed(cnx) def process_value(self, value, description, encoding='utf-8', binarywrap=None): |