mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-15 19:31:54 +08:00
* Bump version to 1.1.9
* Reworked Unicode support; please test * Make Binary() create an array('c') * Clean up Cursors a bit. * Add a TimeDelta factory function, even though not in the API spec.
This commit is contained in:
@ -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."""
|
||||
|
@ -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):
|
||||
"""
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -73,9 +73,12 @@ 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
|
||||
self._result = self._get_result()
|
||||
@ -225,9 +228,12 @@ 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
|
||||
|
@ -8,6 +8,7 @@ from datetime import date, datetime, time, timedelta
|
||||
|
||||
Date = date
|
||||
Time = time
|
||||
TimeDelta = timedelta
|
||||
Timestamp = datetime
|
||||
|
||||
DateTimeDeltaType = timedelta
|
||||
|
@ -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
|
||||
|
@ -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":
|
||||
|
Reference in New Issue
Block a user