Python 2.5 & python-mysqldb : TypeError: not all arguments converted during string formatting

Баг в python-mysqldb Debian 5.0.6

Фаил : /usr/site/lib/python2.5/site-packages/MySQLdb/cursors.py

Пакет :

Package: python-mysqldb
Priority: optional
Section: python
Installed-Size: 360
Maintainer: Debian Python Modules Team Architecture: amd64
Version: 1.2.2-7

Пример :

sql = '''INSERT INTO call_fail_log (`callerid`,`date_stamp`,`cause`) VALUES(%s,FROM_UNIXTIME(%s),%s)'''
        cursor = self.db_init().cursor()
        cursor.executemany(sql,[(callerid,datestamp,cause)])
        self.db_init().close()

Третий плейсхолдер не работоспособен, причина — неправильная работа регулярного вырождения при парсинге.

Решение :

Патч.

--- cursors.py~ 2007-02-11 07:48:19.000000000 -0800
 +++ cursors.py 2008-10-09 14:31:27.000000000 -0700
 @@ -6,7 +6,14 @@
 """

 import re
 -insert_values =
 re.compile(r"
\svalues\s*(\(((?<!\\)'.*?\).*(?<!\\)?'|.)+?\))",
 re.IGNORECASE)
 +
 +restr = (r"
\svalues\s*"
 + r"
(\(((?<!\\)'[^\)]*?\)[^\)]*(?<!\\)?'"
 + r"
|[^\(\)]|"
 + r"
(?:\([^\)]*\))"
 + r"
)+\))")
 +
 +insert_values= re.compile(restr)
 from _mysql_exceptions import Warning, Error, InterfaceError, DataError,
 \
DatabaseError, OperationalError, IntegrityError, InternalError, \
NotSupportedError, ProgrammingError

Накладываем патч на /usr/site/lib/python2.5/site-packages/MySQLdb/cursors.py , радуемся.

Оставить комментарий


Примечание - Вы можете использовать эти HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>