mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-16 03:50:43 +08:00
Bug fixes.
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
%define ver 0.2.0
|
||||
%define ver 0.2.1
|
||||
%define rel 1
|
||||
Summary: Python interface to MySQL-3.22
|
||||
Name: MySQL-python
|
||||
@ -6,8 +6,8 @@ Version: %ver
|
||||
Release: %rel
|
||||
Copyright: Python-style
|
||||
Group: Applications/Databases
|
||||
Source: ftp://starsip.python.net/pub/crew/adustman/MySQLdb-%ver.tar.gz
|
||||
URL: http://starship.python.net/crew/adustman
|
||||
Source: http://dustman.net/andy/python/MySQLdb/%ver/MySQLdb-%ver.tar.gz
|
||||
URL: http://dustman.net/andy/python/MySQLdb
|
||||
Requires: python >= 1.5.2
|
||||
BuildRoot: /tmp/mysqldb-root
|
||||
Packager: Andy Dustman <adustman@comstar.net>
|
||||
|
@ -136,7 +136,7 @@ insert_values = re.compile(r'values\s(\(.+\))', re.IGNORECASE)
|
||||
def escape_dict(d, qc):
|
||||
d2 = {}
|
||||
for k,v in d.items():
|
||||
d2[k] = qc.get(type(v), String2literal)(v)
|
||||
d2[k] = qc.get(type(v), String2Literal)(v)
|
||||
return d2
|
||||
|
||||
|
||||
@ -149,13 +149,11 @@ class BaseCursor:
|
||||
|
||||
See the MySQL docs for more information."""
|
||||
|
||||
def __init__(self, connection, warnings=1):
|
||||
def __init__(self, connection):
|
||||
self.connection = connection
|
||||
self.description = None
|
||||
self.rowcount = -1
|
||||
self.result = None
|
||||
self.arraysize = 100
|
||||
self.warnings = warnings
|
||||
|
||||
def close(self):
|
||||
self.connection = None
|
||||
@ -220,17 +218,26 @@ class BaseCursor:
|
||||
for a in args[1:]: q.append(qv % escape(a, qc))
|
||||
return self._query(join(q, ',\n'))
|
||||
|
||||
def _do_query(self, q):
|
||||
def __do_query(self, q):
|
||||
from string import split, atoi
|
||||
db = self.connection.db
|
||||
print q
|
||||
db.query(q)
|
||||
self.result = self._get_result()
|
||||
self._result = self._get_result()
|
||||
self.rowcount = db.affected_rows()
|
||||
self.description = self.result and self.result.describe() or None
|
||||
self.description = self._result and self._result.describe() or None
|
||||
self._insert_id = db.insert_id()
|
||||
self._info = db.info()
|
||||
self._check_for_warnings()
|
||||
return self.rowcount
|
||||
|
||||
_query = _do_query
|
||||
def _check_for_warnings(self): pass
|
||||
|
||||
_query = __do_query
|
||||
|
||||
def info(self):
|
||||
try: return self._info
|
||||
except AttributeError: raise ProgrammingError, "execute() first"
|
||||
|
||||
def insert_id(self):
|
||||
try: return self._insert_id
|
||||
@ -241,28 +248,26 @@ class BaseCursor:
|
||||
|
||||
class CursorWarningMixIn:
|
||||
|
||||
def _query(self, q):
|
||||
def _check_for_warnings(self):
|
||||
from string import atoi, split
|
||||
r = self._do_query(q)
|
||||
w = self.connection.db.info()
|
||||
if w:
|
||||
warnings = atoi(split(w)[-1])
|
||||
if self._info:
|
||||
warnings = atoi(split(self._info)[-1])
|
||||
if warnings:
|
||||
raise Warning, w
|
||||
return r
|
||||
raise Warning, self.info
|
||||
|
||||
|
||||
class CursorStoreResultMixIn:
|
||||
|
||||
def _get_result(self): return self.connection.db.store_result()
|
||||
|
||||
def _do_query(self, q):
|
||||
def _query(self, q):
|
||||
self.connection._acquire()
|
||||
try:
|
||||
BaseCursor._do_query(self, q)
|
||||
self._rows = self.result and self._fetch_all_rows() or ()
|
||||
rowcount = self._BaseCursor__do_query(q)
|
||||
self._rows = self._result and self._fetch_all_rows() or ()
|
||||
self._pos = 0
|
||||
del self.result
|
||||
del self._result
|
||||
return rowcount
|
||||
finally:
|
||||
self.connection._release()
|
||||
|
||||
@ -300,18 +305,18 @@ class CursorStoreResultMixIn:
|
||||
|
||||
class CursorUseResultMixIn:
|
||||
|
||||
def __init__(self, name=""):
|
||||
BaseCursor.__init__(self, name="")
|
||||
def __init__(self, connection):
|
||||
BaseCursor.__init__(self, connection)
|
||||
if not self.connection._acquire(0):
|
||||
raise ProgrammingError, "would deadlock"
|
||||
|
||||
def close(self):
|
||||
self.connection._release()
|
||||
if self.connection: self.connection._release()
|
||||
self.connection = None
|
||||
|
||||
def __del__(self):
|
||||
try:
|
||||
del self.result
|
||||
del self._result
|
||||
finally:
|
||||
self.close()
|
||||
|
||||
@ -340,16 +345,16 @@ class CursorUseResultMixIn:
|
||||
|
||||
class CursorTupleRowsMixIn:
|
||||
|
||||
def _fetch_row(self): return self.result.fetch_row()
|
||||
def _fetch_rows(self, size): return self.result.fetch_rows(size)
|
||||
def _fetch_all_rows(self): return self.result.fetch_all_rows()
|
||||
def _fetch_row(self): return self._result.fetch_row()
|
||||
def _fetch_rows(self, size): return self._result.fetch_rows(size)
|
||||
def _fetch_all_rows(self): return self._result.fetch_all_rows()
|
||||
|
||||
|
||||
class CursorDictRowsMixIn:
|
||||
|
||||
def _fetch_row(self): return self.result.fetch_row_as_dict()
|
||||
def _fetch_rows(self, size): return self.result.fetch_rows_as_dict(size)
|
||||
def _fetch_all_rows(self): return self.result.fetch_all_rows_as_dict()
|
||||
def _fetch_row(self): return self._result.fetch_row_as_dict()
|
||||
def _fetch_rows(self, size): return self._result.fetch_rows_as_dict(size)
|
||||
def _fetch_all_rows(self): return self._result.fetch_all_rows_as_dict()
|
||||
|
||||
## XXX Deprecated
|
||||
|
||||
@ -363,14 +368,25 @@ class CursorDictRowsMixIn:
|
||||
return apply(self.fetchall, args, kwargs)
|
||||
|
||||
|
||||
class Cursor(CursorWarningMixIn, CursorStoreResultMixIn,
|
||||
CursorTupleRowsMixIn, BaseCursor): pass
|
||||
class DictCursor(CursorWarningMixIn, CursorStoreResultMixIn,
|
||||
CursorDictRowsMixIn, BaseCursor): pass
|
||||
class SSCursor(CursorWarningMixIn, CursorUseResultMixIn,
|
||||
CursorTupleRowsMixIn, BaseCursor): pass
|
||||
class SSDictCursor(CursorWarningMixIn, CursorUseResultMixIn,
|
||||
CursorDictRowsMixIn, BaseCursor): pass
|
||||
class CursorNW(CursorStoreResultMixIn, CursorTupleRowsMixIn,
|
||||
BaseCursor): pass
|
||||
|
||||
class Cursor(CursorWarningMixIn, CursorNW): pass
|
||||
|
||||
class DictCursorNW(CursorStoreResultMixIn, CursorDictRowsMixIn,
|
||||
BaseCursor): pass
|
||||
|
||||
class DictCursor(CursorWarningMixIn, DictCursorNW): pass
|
||||
|
||||
class SSCursorNW(CursorUseResultMixIn, CursorTupleRowsMixIn,
|
||||
BaseCursor): pass
|
||||
|
||||
class SSCursor(CursorWarningMixIn, SSCursorNW): pass
|
||||
|
||||
class SSDictCursorNW(CursorUseResultMixIn, CursorDictRowsMixIn,
|
||||
BaseCursor): pass
|
||||
|
||||
class SSDictCursor(CursorWarningMixIn, SSDictCursorNW): pass
|
||||
|
||||
|
||||
class Connection:
|
||||
|
@ -115,7 +115,7 @@ the patch. If that fails, read the FAQ.
|
||||
and may reflect features of the next release.
|
||||
<sect1>FAQs
|
||||
<p>A FAQ is available at
|
||||
<htmlurl url="http://starship.python.net/crew/adustman/MySQLdb-FAQ.html">.
|
||||
<htmlurl url="http://dustman.net/andy/python/MySQLdb-FAQ.html">.
|
||||
<sect>_mysql module<label id="_mysql">
|
||||
<P>
|
||||
If you want to write applications which are portable across databases,
|
||||
@ -371,7 +371,7 @@ creating a new subclass, assuming the new database is reasonably
|
||||
standard.
|
||||
|
||||
For an example of this, see the author's
|
||||
<htmlurl url="http://starship.python.net/crew/adustman"
|
||||
<htmlurl url="http://dustman.net/andy/python"
|
||||
name="SQLDict module">, which allows standard queries to be
|
||||
defined and accessed using an object which looks like a
|
||||
dictionary, and reads/writes user-defined objects.
|
||||
@ -381,7 +381,8 @@ you can easily derive your own subclasses. There are several Cursor
|
||||
classes in MySQLdb:
|
||||
<p>
|
||||
<descrip>
|
||||
<tag>CursorBase</tag> The base class for Cursor objects.
|
||||
<tag>BaseCursor</tag> The base class for Cursor objects.
|
||||
This does not raise Warnings.
|
||||
|
||||
<tag>CursorWarningMixIn</tag> Causes the Warning exception to be raised
|
||||
on queries which produce warnings.
|
||||
@ -428,6 +429,8 @@ Use only if you are dealing with potentially large result sets.
|
||||
<tag/SSDictCursor/ Like <tt/SSCursor/ except it returns rows as
|
||||
dictionaries.
|
||||
|
||||
<tag/XXXCursorNW/> Cursors with the "NW" suffix do not raise Warnings.
|
||||
|
||||
</descrip>
|
||||
<p>For an example of how to use these classes,
|
||||
read the code. If you need something more exotic than this,
|
||||
|
Reference in New Issue
Block a user