diff --git a/MySQLdb/MySQLdb/__init__.py b/MySQLdb/MySQLdb/__init__.py index 673f64c..43ec232 100644 --- a/MySQLdb/MySQLdb/__init__.py +++ b/MySQLdb/MySQLdb/__init__.py @@ -18,7 +18,7 @@ __revision__ = """$Revision$"""[11:-2] version_info = ( 1, 1, - 8, + 9, "final", 1) if version_info[3] == "final": __version__ = "%d.%d.%d" % version_info[:3] @@ -56,7 +56,9 @@ TIMESTAMP = DBAPISet(FIELD_TYPE.TIMESTAMP, FIELD_TYPE.DATETIME) DATETIME = TIMESTAMP ROWID = DBAPISet() -def Binary(x): return str(x) +def Binary(x): + from array import array + return array('c', x) def Connect(*args, **kwargs): """Factory function for connections.Connection.""" diff --git a/MySQLdb/MySQLdb/connections.py b/MySQLdb/MySQLdb/connections.py index 17db7f8..5999f76 100644 --- a/MySQLdb/MySQLdb/connections.py +++ b/MySQLdb/MySQLdb/connections.py @@ -61,13 +61,12 @@ class Connection(_mysql.connection): read_default_file -- file from which default client values are read read_default_group -- configuration group to use from the default file cursorclass -- class object, used to create cursors (keyword only) - unicode -- If set to a string, character columns are returned as - unicode objects with this encoding. If set to None, the - default encoding is used. If not set at all, character - columns are returned as normal strings. - unicode_errors -- If set to a string, this is used as the errors - parameter to the unicode function; by default it is - 'strict'. See documentation for unicode for more details. + use_unicode -- If True, text-like columns are returned as + unicode objects using the connection's character set. + Otherwise, text-like columns are returned as strings. + columns are returned as normal strings. Unicode objects + will always be encoded to the connection's character set + regardless of this setting. client_flag -- integer, flags to use or 0 (see MySQL docs or constants/CLIENTS.py) ssl -- dictionary or mapping, contains SSL connection parameters; see @@ -92,22 +91,19 @@ class Connection(_mysql.connection): del kwargs2['cursorclass'] else: self.cursorclass = self.default_cursor - self.charset = None - if kwargs.has_key('unicode'): - charset = kwargs['unicode'] - errors = kwargs.get('unicode_errors', 'strict') - del kwargs2['unicode'] - if kwargs.has_key('unicode_errors'): - del kwargs2['unicode_errors'] - if charset: - self.charset = charset - def u(s, c=charset, e=errors): return unicode(s, c, e) - else: - u = unicode - conv[FIELD_TYPE.STRING] = u - conv[FIELD_TYPE.VAR_STRING] = u - conv[FIELD_TYPE.BLOB].insert(-1, (None, u)) + use_unicode = kwargs.get('use_unicode', 0) + if kwargs.has_key('use_unicode'): + del kwargs2['use_unicode'] + super(Connection, self).__init__(*args, **kwargs2) + + self.charset = self.character_set_name().split('_')[0] + + if use_unicode: + conv[FIELD_TYPE.STRING] = unicode + conv[FIELD_TYPE.VAR_STRING] = unicode + conv[FIELD_TYPE.BLOB].insert(-1, (None, unicode)) + self.converter[types.StringType] = self.string_literal self.converter[types.UnicodeType] = self.unicode_literal self._transactional = self.server_capabilities & CLIENT.TRANSACTIONS @@ -116,12 +112,6 @@ class Connection(_mysql.connection): self.autocommit(0) self.messages = [] - def __del__(self): - try: - self.close() - except: - pass - def cursor(self, cursorclass=None): """ diff --git a/MySQLdb/MySQLdb/converters.py b/MySQLdb/MySQLdb/converters.py index 04d28b1..412a99c 100644 --- a/MySQLdb/MySQLdb/converters.py +++ b/MySQLdb/MySQLdb/converters.py @@ -42,8 +42,10 @@ def Thing2Str(s, d): return str(s) def Unicode2Str(s, d): - """Convert a unicode object to a string using latin1 encoding.""" - return s.encode('latin') + """Convert a unicode object to a string using the default encoding. + This is only used as a placeholder for the real function, which + is connection-dependent.""" + return s.encode() Long2Int = Thing2Str diff --git a/MySQLdb/MySQLdb/cursors.py b/MySQLdb/MySQLdb/cursors.py index 5ef43e4..640de7d 100644 --- a/MySQLdb/MySQLdb/cursors.py +++ b/MySQLdb/MySQLdb/cursors.py @@ -73,8 +73,11 @@ class BaseCursor(object): if nr == -1: return None self._do_get_result() + self._post_get_result() self._warning_check() return 1 + + def _post_get_result(self): pass def _do_get_result(self): db = self.connection @@ -225,10 +228,13 @@ class CursorStoreResultMixIn(object): def _query(self, q): rowcount = self._do_query(q) + self._post_get_result() + return rowcount + + def _post_get_result(self): self._rows = self._fetch_row(0) self._result = None - return rowcount - + def fetchone(self): """Fetches a single row from the cursor. None indicates that no more rows are available.""" diff --git a/MySQLdb/MySQLdb/pytimes.py b/MySQLdb/MySQLdb/pytimes.py index d5cc74a..817dbbf 100644 --- a/MySQLdb/MySQLdb/pytimes.py +++ b/MySQLdb/MySQLdb/pytimes.py @@ -8,6 +8,7 @@ from datetime import date, datetime, time, timedelta Date = date Time = time +TimeDelta = timedelta Timestamp = datetime DateTimeDeltaType = timedelta diff --git a/MySQLdb/_mysql.c b/MySQLdb/_mysql.c index 5cb787b..7c32534 100644 --- a/MySQLdb/_mysql.c +++ b/MySQLdb/_mysql.c @@ -1,5 +1,5 @@ -#define version_info "(1,1,8,'final',1)" -#define __version__ "1.1.8" +#define version_info "(1,1,9,'final',1)" +#define __version__ "1.1.9" /* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/MySQLdb/setup.py b/MySQLdb/setup.py index 550e74f..82d07b6 100644 --- a/MySQLdb/setup.py +++ b/MySQLdb/setup.py @@ -37,7 +37,7 @@ embedded_server = (mysqlclient == 'mysqld') name = "MySQL-%s" % os.path.basename(sys.executable) if embedded_server: name = name + "-embedded" -version = "1.1.8" +version = "1.1.9" def config(what): if sys.platform == "win32":