mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-15 11:10:58 +08:00
Raise ProgrammingError for nan and inf (#314)
* Raise ProgrammingError when inf or nan is passed Fixes #246 * Rename _mysql_exceptions -> _exceptions
This commit is contained in:
@ -1,15 +1,10 @@
|
||||
"""_mysql_exceptions: Exception classes for _mysql and MySQLdb.
|
||||
"""Exception classes for _mysql and MySQLdb.
|
||||
|
||||
These classes are dictated by the DB API v2.0:
|
||||
|
||||
https://www.python.org/dev/peps/pep-0249/
|
||||
"""
|
||||
|
||||
try:
|
||||
from exceptions import Exception, StandardError, Warning
|
||||
except ImportError:
|
||||
# Python 3
|
||||
StandardError = Exception
|
||||
from .compat import StandardError
|
||||
|
||||
|
||||
class MySQLError(StandardError):
|
||||
@ -20,6 +15,7 @@ class Warning(Warning, MySQLError):
|
||||
"""Exception raised for important warnings like data truncations
|
||||
while inserting, etc."""
|
||||
|
||||
|
||||
class Error(MySQLError):
|
||||
"""Exception that is the base class of all other error exceptions
|
||||
(not Warning)."""
|
@ -2669,7 +2669,7 @@ init_mysql(void)
|
||||
(PyObject *)&_mysql_ResultObject_Type))
|
||||
goto error;
|
||||
Py_INCREF(&_mysql_ResultObject_Type);
|
||||
if (!(emod = PyImport_ImportModule("MySQLdb._mysql_exceptions"))) {
|
||||
if (!(emod = PyImport_ImportModule("MySQLdb._exceptions"))) {
|
||||
PyErr_Print();
|
||||
goto error;
|
||||
}
|
||||
|
@ -5,8 +5,10 @@ if sys.version_info[0] == 2:
|
||||
unicode = unicode
|
||||
unichr = unichr
|
||||
long = long
|
||||
StandardError = StandardError
|
||||
else:
|
||||
PY2 = False
|
||||
unicode = str
|
||||
unichr = chr
|
||||
long = int
|
||||
StandardError = Exception
|
||||
|
@ -9,7 +9,7 @@ import sys
|
||||
|
||||
from MySQLdb import cursors, _mysql
|
||||
from MySQLdb.compat import unicode, PY2
|
||||
from MySQLdb._mysql_exceptions import (
|
||||
from MySQLdb._exceptions import (
|
||||
Warning, Error, InterfaceError, DataError,
|
||||
DatabaseError, OperationalError, IntegrityError, InternalError,
|
||||
NotSupportedError, ProgrammingError,
|
||||
|
@ -36,6 +36,7 @@ from MySQLdb._mysql import string_literal, escape
|
||||
from MySQLdb.constants import FIELD_TYPE, FLAG
|
||||
from MySQLdb.times import *
|
||||
from MySQLdb.compat import PY2, long, unicode
|
||||
from MySQLdb._exceptions import ProgrammingError
|
||||
|
||||
NoneType = type(None)
|
||||
|
||||
@ -66,6 +67,8 @@ def Unicode2Str(s, d):
|
||||
|
||||
def Float2Str(o, d):
|
||||
s = repr(o)
|
||||
if s in ('inf', 'nan'):
|
||||
raise ProgrammingError("%s can not be used with MySQL" % s)
|
||||
if 'e' not in s:
|
||||
s += 'e0'
|
||||
return s
|
||||
|
@ -9,7 +9,7 @@ import re
|
||||
import sys
|
||||
|
||||
from .compat import unicode
|
||||
from ._mysql_exceptions import (
|
||||
from ._exceptions import (
|
||||
Warning, Error, InterfaceError, DataError,
|
||||
DatabaseError, OperationalError, IntegrityError, InternalError,
|
||||
NotSupportedError, ProgrammingError)
|
||||
@ -48,7 +48,7 @@ class BaseCursor(object):
|
||||
#: Default value of max_allowed_packet is 1048576.
|
||||
max_stmt_length = 64*1024
|
||||
|
||||
from ._mysql_exceptions import (
|
||||
from ._exceptions import (
|
||||
MySQLError, Warning, Error, InterfaceError,
|
||||
DatabaseError, DataError, OperationalError, IntegrityError,
|
||||
InternalError, ProgrammingError, NotSupportedError,
|
||||
|
Reference in New Issue
Block a user