@@ -187,7 +187,7 @@ def execute(self, query, args=None):
187
187
parameter placeholder in the query. If a mapping is used,
188
188
%(key)s must be used as the placeholder.
189
189
190
- Returns long integer rows affected, if any
190
+ Returns integer represents rows affected, if any
191
191
"""
192
192
while self .nextset ():
193
193
pass
@@ -208,27 +208,25 @@ def execute(self, query, args=None):
208
208
args = dict ((key , db .literal (item )) for key , item in args .items ())
209
209
else :
210
210
args = tuple (map (db .literal , args ))
211
- if not PY2 and isinstance (query , bytes ):
211
+ if not PY2 and isinstance (query , ( bytes , bytearray ) ):
212
212
query = query .decode (db .unicode_literal .charset )
213
- query = query % args
213
+ try :
214
+ query = query % args
215
+ except TypeError as m :
216
+ self .errorhandler (self , ProgrammingError , str (m ))
214
217
215
218
if isinstance (query , unicode ):
216
219
query = query .encode (db .unicode_literal .charset , 'surrogateescape' )
217
220
218
221
res = None
219
222
try :
220
223
res = self ._query (query )
221
- except TypeError as m :
222
- if m .args [0 ] in ("not enough arguments for format string" ,
223
- "not all arguments converted" ):
224
- self .errorhandler (self , ProgrammingError , m .args [0 ])
225
- else :
226
- self .errorhandler (self , TypeError , m )
227
224
except Exception :
228
225
exc , value = sys .exc_info ()[:2 ]
229
226
self .errorhandler (self , exc , value )
230
227
self ._executed = query
231
- if not self ._defer_warnings : self ._warning_check ()
228
+ if not self ._defer_warnings :
229
+ self ._warning_check ()
232
230
return res
233
231
234
232
def executemany (self , query , args ):
@@ -369,13 +367,13 @@ def __iter__(self):
369
367
370
368
371
369
class CursorStoreResultMixIn (object ):
372
-
373
370
"""This is a MixIn class which causes the entire result set to be
374
371
stored on the client side, i.e. it uses mysql_store_result(). If the
375
372
result set can be very large, consider adding a LIMIT clause to your
376
373
query, or using CursorUseResultMixIn instead."""
377
374
378
- def _get_result (self ): return self ._get_db ().store_result ()
375
+ def _get_result (self ):
376
+ return self ._get_db ().store_result ()
379
377
380
378
def _query (self , q ):
381
379
rowcount = self ._do_query (q )
@@ -390,9 +388,10 @@ def fetchone(self):
390
388
"""Fetches a single row from the cursor. None indicates that
391
389
no more rows are available."""
392
390
self ._check_executed ()
393
- if self .rownumber >= len (self ._rows ): return None
391
+ if self .rownumber >= len (self ._rows ):
392
+ return None
394
393
result = self ._rows [self .rownumber ]
395
- self .rownumber = self .rownumber + 1
394
+ self .rownumber = self .rownumber + 1
396
395
return result
397
396
398
397
def fetchmany (self , size = None ):
0 commit comments