45
45
46
46
class BaseCursor (object ):
47
47
"""A base for Cursor classes. Useful attributes:
48
-
48
+
49
49
description
50
50
A tuple of DB API 7-tuples describing the columns in
51
51
the last executed query; see PEP-249 for details.
@@ -55,20 +55,20 @@ class BaseCursor(object):
55
55
in the result set. Values correspond to those in
56
56
MySQLdb.constants.FLAG. See MySQL documentation (C API)
57
57
for more information. Non-standard extension.
58
-
58
+
59
59
arraysize
60
60
default number of rows fetchmany() will fetch
61
61
"""
62
62
63
63
from _mysql_exceptions import MySQLError , Warning , Error , InterfaceError , \
64
64
DatabaseError , DataError , OperationalError , IntegrityError , \
65
65
InternalError , ProgrammingError , NotSupportedError
66
-
66
+
67
67
_defer_warnings = False
68
-
68
+
69
69
def __init__ (self , connection ):
70
70
from weakref import ref
71
-
71
+
72
72
self .connection = ref (connection )
73
73
self .description = None
74
74
self .description_flags = None
@@ -82,7 +82,7 @@ def __init__(self, connection):
82
82
self ._warnings = 0
83
83
self ._info = None
84
84
self .rownumber = None
85
-
85
+
86
86
def close (self ):
87
87
"""Close the cursor. No further queries will be possible."""
88
88
try :
@@ -124,7 +124,10 @@ def _warning_check(self):
124
124
for w in warnings :
125
125
self .messages .append ((self .Warning , w ))
126
126
for w in warnings :
127
- warn (w [- 1 ], self .Warning , 3 )
127
+ msg = w [- 1 ]
128
+ if not PY2 and isinstance (msg , bytes ):
129
+ msg = msg .decode ()
130
+ warn (msg , self .Warning , 3 )
128
131
elif self ._info :
129
132
self .messages .append ((self .Warning , self ._info ))
130
133
warn (self ._info , self .Warning , 3 )
@@ -159,10 +162,10 @@ def _do_get_result(self):
159
162
self .lastrowid = db .insert_id ()
160
163
self ._warnings = db .warning_count ()
161
164
self ._info = db .info ()
162
-
165
+
163
166
def setinputsizes (self , * args ):
164
167
"""Does nothing, required by DB API."""
165
-
168
+
166
169
def setoutputsizes (self , * args ):
167
170
"""Does nothing, required by DB API."""
168
171
@@ -173,10 +176,10 @@ def _get_db(self):
173
176
if con is None :
174
177
raise ProgrammingError ("cursor closed" )
175
178
return con
176
-
179
+
177
180
def execute (self , query , args = None ):
178
181
"""Execute a query.
179
-
182
+
180
183
query -- string, query to execute on server
181
184
args -- optional sequence or mapping, parameters to use with query.
182
185
0 commit comments