mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-15 11:10:58 +08:00
Fixes to work with MySQLdb-0.9.0.
A plus or minus in front of the database name can force transactions on or off. Make use of MySQLdb.conversions. Only the SQL -> Python conversions are actually used by ZMySQLDA. A minor bug in MySQLdb-0.9.0c1 keeps it from working with this, only seen with not using mx.DateTime. Fixed in CVS. Will release 0.9.0c2 before doing another ZMySQLDA release.
This commit is contained in:
@ -1 +1 @@
|
||||
ZMySQLDA 2.0.6
|
||||
ZMySQLDA 2.0.7b1
|
||||
|
@ -49,7 +49,7 @@
|
||||
The connection string used for Z MySQL Database Connection
|
||||
is of the form:
|
||||
<pre>
|
||||
database[@host[:port]] [user [password [unix_socket]]]
|
||||
[+/-]database[@host[:port]] [user [password [unix_socket]]]
|
||||
</pre>
|
||||
or typically:
|
||||
<pre>
|
||||
@ -59,7 +59,15 @@
|
||||
Only specify host if the server is on a remote system. You can
|
||||
use a non-standard port, if necessary. If the UNIX socket is in
|
||||
a non-standard location, you can specify the full path to it
|
||||
after the password.
|
||||
after the password. A '-' in front of the database tells ZMySQLDA
|
||||
to not use Zope's Transaction Manager, even if the server supports
|
||||
transactions. A '+' in front of the database tells ZMySQLDA that
|
||||
it must use transactions; an exception will be raised if they are
|
||||
not supported by the server. If neither '-' or '+' are present,
|
||||
then transactions will be enabled if the server supports them.
|
||||
If you are using non-transaction safe tables (TSTs) on a server that
|
||||
supports TSTs, use '-'. If you require transactions, use '+'. If
|
||||
you aren't sure, don't use either.
|
||||
</dd></dl>
|
||||
|
||||
</body>
|
||||
|
@ -87,6 +87,7 @@
|
||||
__version__='$Revision$'[11:-2]
|
||||
|
||||
import _mysql
|
||||
from MySQLdb.converters import conversions
|
||||
from MySQLdb.constants import FIELD_TYPE, CR, CLIENT
|
||||
from _mysql_exceptions import OperationalError
|
||||
from Shared.DC.ZRDB.TM import TM
|
||||
@ -101,6 +102,8 @@ hosed_connection = (
|
||||
CR.SERVER_LOST
|
||||
)
|
||||
|
||||
MySQLdb_version_required = (0,9,0)
|
||||
|
||||
def _mysql_timestamp_converter(s):
|
||||
if len(s) < 14:
|
||||
s = s + "0"*(14-len(s))
|
||||
@ -139,19 +142,10 @@ class DB(TM):
|
||||
FIELD_TYPE.BLOB: "BLOB", FIELD_TYPE.STRING: "STRING",
|
||||
}
|
||||
|
||||
conv={
|
||||
FIELD_TYPE.TIMESTAMP: _mysql_timestamp_converter,
|
||||
FIELD_TYPE.TINY: int,
|
||||
FIELD_TYPE.SHORT: int,
|
||||
FIELD_TYPE.LONG: long,
|
||||
FIELD_TYPE.FLOAT: float,
|
||||
FIELD_TYPE.DOUBLE: float,
|
||||
FIELD_TYPE.LONGLONG: long,
|
||||
FIELD_TYPE.INT24: int,
|
||||
FIELD_TYPE.YEAR: int,
|
||||
FIELD_TYPE.DATETIME: DateTime_or_None,
|
||||
FIELD_TYPE.DATE: DateTime_or_None,
|
||||
}
|
||||
conv=conversions.copy()
|
||||
conv[FIELD_TYPE.DATETIME] = DateTime_or_None
|
||||
conv[FIELD_TYPE.DATE] = DateTime_or_None
|
||||
del conv[FIELD_TYPE.TIME]
|
||||
|
||||
_p_oid=_p_changed=_registered=None
|
||||
|
||||
@ -159,7 +153,16 @@ class DB(TM):
|
||||
self.connection=connection
|
||||
self.kwargs = kwargs = self._parse_connection_string(connection)
|
||||
self.db=apply(self.Database_Connection, (), kwargs)
|
||||
v = self.db.hasattr('version_info', (0,0,0))
|
||||
if v < MySQLdb_version_required:
|
||||
raise NotSupportedError, \
|
||||
"ZMySQLDA requires at least MySQLdb %s, %s found" % \
|
||||
(MySQLdb_version_required, v)
|
||||
self.transactions = self.db.server_capabilities & CLIENT.TRANSACTIONS
|
||||
if self._try_transactions == '-':
|
||||
self.transactions = 0
|
||||
elif not self.transactions and self._try_transactions == '+':
|
||||
raise NotSupportedError, "transactions supported by this server"
|
||||
|
||||
def _parse_connection_string(self, connection):
|
||||
kwargs = {'conv': self.conv}
|
||||
@ -175,6 +178,11 @@ class DB(TM):
|
||||
kwargs['host'] = host
|
||||
else:
|
||||
kwargs['db'] = db_host
|
||||
if kwargs['db'][0] in ('+', '-'):
|
||||
self._try_transactions = kwargs['db'][0]
|
||||
kwargs['db'] = kwargs['db'][1:]
|
||||
else:
|
||||
self._try_transactions = None
|
||||
if not items: return kwargs
|
||||
kwargs['user'], items = items[0], items[1:]
|
||||
if not items: return kwargs
|
||||
|
Reference in New Issue
Block a user