summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>2008-02-22 15:53:34 +0100
committerAdrien Di Mascio <Adrien.DiMascio@logilab.fr>2008-02-22 15:53:34 +0100
commitc117ee67f44134efc9d7c04c74abd005b2788cd0 (patch)
treea0678143fa6b54aee8769818f0b2cb3eca359634
parente11c1930c761eebea7e07733da25cb6c3590c3d2 (diff)
parentebd44268aa6b18b021775813b4e03690c3f26611 (diff)
downloadlogilab-common-c117ee67f44134efc9d7c04c74abd005b2788cd0.tar.gz
merge
-rw-r--r--ChangeLog4
-rw-r--r--adbh.py13
-rw-r--r--db.py28
-rw-r--r--debian/copyright2
4 files changed, 44 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 734cbab..2d057e6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,10 @@
ChangeLog for logilab.common
============================
+ --
+ * adbh: mysql doesn't support ILIKE, implement list_indices for mysql
+ * db: mysql adapter use mx DateTime when available, fix unicode handling
+
2008-02-18 -- 0.28.2
* testlib: restore python2.3 compatiblity
diff --git a/adbh.py b/adbh.py
index f18ba8b..0efbf9c 100644
--- a/adbh.py
+++ b/adbh.py
@@ -418,9 +418,10 @@ class _SqliteAdvFuncHelper(_GenericAdvFuncHelper):
class _MyAdvFuncHelper(_GenericAdvFuncHelper):
- """Postgres helper, taking advantage of postgres SEQUENCE support
+ """MySQL helper, taking advantage of postgres SEQUENCE support
"""
needs_from_clause = True
+ ilike_support = False # insensitive search by default
# modifiable but should not be shared
FUNCTIONS = _GenericAdvFuncHelper.FUNCTIONS.copy()
@@ -495,6 +496,16 @@ class _MyAdvFuncHelper(_GenericAdvFuncHelper):
cursor.execute("SHOW TABLES")
return [r[0] for r in cursor.fetchall()]
+ def list_indices(self, cursor, table=None):
+ """return the list of indices of a database, only for the given table if specified"""
+ if table:
+ cursor.execute("SHOW INDEX FROM %s" % table)
+ return [r[2] for r in cursor.fetchall()]
+ allindices = []
+ for table in self.list_tables(cursor):
+ allindices += self.list_indices(cursor, table)
+ return allindices
+
ADV_FUNC_HELPER_DIRECTORY = {'postgres': _PGAdvFuncHelper(),
diff --git a/db.py b/db.py
index 0c21d1a..7818046 100644
--- a/db.py
+++ b/db.py
@@ -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):
diff --git a/debian/copyright b/debian/copyright
index 2da2d36..61bd575 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -8,7 +8,7 @@ Upstream Author:
Copyright:
-Copyright (c) 2003-2006 LOGILAB S.A. (Paris, FRANCE).
+Copyright (c) 2003-2008 LOGILAB S.A. (Paris, FRANCE).
http://www.logilab.fr/ -- mailto:contact@logilab.fr
This program is free software; you can redistribute it and/or modify it under