mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-15 11:10:58 +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 = (
|
version_info = (
|
||||||
1,
|
1,
|
||||||
1,
|
1,
|
||||||
8,
|
9,
|
||||||
"final",
|
"final",
|
||||||
1)
|
1)
|
||||||
if version_info[3] == "final": __version__ = "%d.%d.%d" % version_info[:3]
|
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
|
DATETIME = TIMESTAMP
|
||||||
ROWID = DBAPISet()
|
ROWID = DBAPISet()
|
||||||
|
|
||||||
def Binary(x): return str(x)
|
def Binary(x):
|
||||||
|
from array import array
|
||||||
|
return array('c', x)
|
||||||
|
|
||||||
def Connect(*args, **kwargs):
|
def Connect(*args, **kwargs):
|
||||||
"""Factory function for connections.Connection."""
|
"""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_file -- file from which default client values are read
|
||||||
read_default_group -- configuration group to use from the default file
|
read_default_group -- configuration group to use from the default file
|
||||||
cursorclass -- class object, used to create cursors (keyword only)
|
cursorclass -- class object, used to create cursors (keyword only)
|
||||||
unicode -- If set to a string, character columns are returned as
|
use_unicode -- If True, text-like columns are returned as
|
||||||
unicode objects with this encoding. If set to None, the
|
unicode objects using the connection's character set.
|
||||||
default encoding is used. If not set at all, character
|
Otherwise, text-like columns are returned as strings.
|
||||||
columns are returned as normal strings.
|
columns are returned as normal strings. Unicode objects
|
||||||
unicode_errors -- If set to a string, this is used as the errors
|
will always be encoded to the connection's character set
|
||||||
parameter to the unicode function; by default it is
|
regardless of this setting.
|
||||||
'strict'. See documentation for unicode for more details.
|
|
||||||
client_flag -- integer, flags to use or 0
|
client_flag -- integer, flags to use or 0
|
||||||
(see MySQL docs or constants/CLIENTS.py)
|
(see MySQL docs or constants/CLIENTS.py)
|
||||||
ssl -- dictionary or mapping, contains SSL connection parameters; see
|
ssl -- dictionary or mapping, contains SSL connection parameters; see
|
||||||
@ -92,22 +91,19 @@ class Connection(_mysql.connection):
|
|||||||
del kwargs2['cursorclass']
|
del kwargs2['cursorclass']
|
||||||
else:
|
else:
|
||||||
self.cursorclass = self.default_cursor
|
self.cursorclass = self.default_cursor
|
||||||
self.charset = None
|
use_unicode = kwargs.get('use_unicode', 0)
|
||||||
if kwargs.has_key('unicode'):
|
if kwargs.has_key('use_unicode'):
|
||||||
charset = kwargs['unicode']
|
del kwargs2['use_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))
|
|
||||||
super(Connection, self).__init__(*args, **kwargs2)
|
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.StringType] = self.string_literal
|
||||||
self.converter[types.UnicodeType] = self.unicode_literal
|
self.converter[types.UnicodeType] = self.unicode_literal
|
||||||
self._transactional = self.server_capabilities & CLIENT.TRANSACTIONS
|
self._transactional = self.server_capabilities & CLIENT.TRANSACTIONS
|
||||||
@ -116,12 +112,6 @@ class Connection(_mysql.connection):
|
|||||||
self.autocommit(0)
|
self.autocommit(0)
|
||||||
self.messages = []
|
self.messages = []
|
||||||
|
|
||||||
def __del__(self):
|
|
||||||
try:
|
|
||||||
self.close()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def cursor(self, cursorclass=None):
|
def cursor(self, cursorclass=None):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -42,8 +42,10 @@ def Thing2Str(s, d):
|
|||||||
return str(s)
|
return str(s)
|
||||||
|
|
||||||
def Unicode2Str(s, d):
|
def Unicode2Str(s, d):
|
||||||
"""Convert a unicode object to a string using latin1 encoding."""
|
"""Convert a unicode object to a string using the default encoding.
|
||||||
return s.encode('latin')
|
This is only used as a placeholder for the real function, which
|
||||||
|
is connection-dependent."""
|
||||||
|
return s.encode()
|
||||||
|
|
||||||
Long2Int = Thing2Str
|
Long2Int = Thing2Str
|
||||||
|
|
||||||
|
@ -73,9 +73,12 @@ class BaseCursor(object):
|
|||||||
if nr == -1:
|
if nr == -1:
|
||||||
return None
|
return None
|
||||||
self._do_get_result()
|
self._do_get_result()
|
||||||
|
self._post_get_result()
|
||||||
self._warning_check()
|
self._warning_check()
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
def _post_get_result(self): pass
|
||||||
|
|
||||||
def _do_get_result(self):
|
def _do_get_result(self):
|
||||||
db = self.connection
|
db = self.connection
|
||||||
self._result = self._get_result()
|
self._result = self._get_result()
|
||||||
@ -225,9 +228,12 @@ class CursorStoreResultMixIn(object):
|
|||||||
|
|
||||||
def _query(self, q):
|
def _query(self, q):
|
||||||
rowcount = self._do_query(q)
|
rowcount = self._do_query(q)
|
||||||
|
self._post_get_result()
|
||||||
|
return rowcount
|
||||||
|
|
||||||
|
def _post_get_result(self):
|
||||||
self._rows = self._fetch_row(0)
|
self._rows = self._fetch_row(0)
|
||||||
self._result = None
|
self._result = None
|
||||||
return rowcount
|
|
||||||
|
|
||||||
def fetchone(self):
|
def fetchone(self):
|
||||||
"""Fetches a single row from the cursor. None indicates that
|
"""Fetches a single row from the cursor. None indicates that
|
||||||
|
@ -8,6 +8,7 @@ from datetime import date, datetime, time, timedelta
|
|||||||
|
|
||||||
Date = date
|
Date = date
|
||||||
Time = time
|
Time = time
|
||||||
|
TimeDelta = timedelta
|
||||||
Timestamp = datetime
|
Timestamp = datetime
|
||||||
|
|
||||||
DateTimeDeltaType = timedelta
|
DateTimeDeltaType = timedelta
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#define version_info "(1,1,8,'final',1)"
|
#define version_info "(1,1,9,'final',1)"
|
||||||
#define __version__ "1.1.8"
|
#define __version__ "1.1.9"
|
||||||
/*
|
/*
|
||||||
This program is free software; you can redistribute it and/or modify
|
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
|
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)
|
name = "MySQL-%s" % os.path.basename(sys.executable)
|
||||||
if embedded_server:
|
if embedded_server:
|
||||||
name = name + "-embedded"
|
name = name + "-embedded"
|
||||||
version = "1.1.8"
|
version = "1.1.9"
|
||||||
|
|
||||||
def config(what):
|
def config(what):
|
||||||
if sys.platform == "win32":
|
if sys.platform == "win32":
|
||||||
|
Reference in New Issue
Block a user