mirror of https://github.com/python/cpython
Issue #3659: Values of string subclasses were not handled correctly when used
as bind parameters. Reviewed by Bejnamin Peterson.
This commit is contained in:
parent
d0db98fcd8
commit
6117f423c4
|
@ -169,6 +169,12 @@ class RegressionTests(unittest.TestCase):
|
||||||
con = sqlite.connect(":memory:")
|
con = sqlite.connect(":memory:")
|
||||||
setattr(con, "isolation_level", "\xe9")
|
setattr(con, "isolation_level", "\xe9")
|
||||||
|
|
||||||
|
def CheckStrSubclass(self):
|
||||||
|
"""
|
||||||
|
The Python 3.0 port of the module didn't cope with values of subclasses of str.
|
||||||
|
"""
|
||||||
|
class MyStr(str): pass
|
||||||
|
self.con.execute("select ?", (MyStr("abc"),))
|
||||||
|
|
||||||
def suite():
|
def suite():
|
||||||
regression_suite = unittest.makeSuite(RegressionTests, "Check")
|
regression_suite = unittest.makeSuite(RegressionTests, "Check")
|
||||||
|
|
|
@ -20,6 +20,11 @@ Library
|
||||||
|
|
||||||
- Bug #3884: Make the turtle module toplevel again.
|
- Bug #3884: Make the turtle module toplevel again.
|
||||||
|
|
||||||
|
Extension Modules
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
- Issue #3659: Subclasses of str didn't work as SQL parameters.
|
||||||
|
|
||||||
|
|
||||||
What's New in Python 3.0 release candidate 1
|
What's New in Python 3.0 release candidate 1
|
||||||
============================================
|
============================================
|
||||||
|
|
|
@ -43,7 +43,6 @@ typedef enum {
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TYPE_LONG,
|
TYPE_LONG,
|
||||||
TYPE_FLOAT,
|
TYPE_FLOAT,
|
||||||
TYPE_STRING,
|
|
||||||
TYPE_UNICODE,
|
TYPE_UNICODE,
|
||||||
TYPE_BUFFER,
|
TYPE_BUFFER,
|
||||||
TYPE_UNKNOWN
|
TYPE_UNKNOWN
|
||||||
|
@ -96,7 +95,6 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
|
||||||
char* string;
|
char* string;
|
||||||
Py_ssize_t buflen;
|
Py_ssize_t buflen;
|
||||||
parameter_type paramtype;
|
parameter_type paramtype;
|
||||||
char* c;
|
|
||||||
|
|
||||||
if (parameter == Py_None) {
|
if (parameter == Py_None) {
|
||||||
rc = sqlite3_bind_null(self->st, pos);
|
rc = sqlite3_bind_null(self->st, pos);
|
||||||
|
@ -114,24 +112,13 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
|
||||||
} else if (PyFloat_Check(parameter)) {
|
} else if (PyFloat_Check(parameter)) {
|
||||||
paramtype = TYPE_FLOAT;
|
paramtype = TYPE_FLOAT;
|
||||||
} else if (PyUnicode_Check(parameter)) {
|
} else if (PyUnicode_Check(parameter)) {
|
||||||
paramtype = TYPE_STRING;
|
paramtype = TYPE_UNICODE;
|
||||||
} else if (PyObject_CheckBuffer(parameter)) {
|
} else if (PyObject_CheckBuffer(parameter)) {
|
||||||
paramtype = TYPE_BUFFER;
|
paramtype = TYPE_BUFFER;
|
||||||
} else {
|
} else {
|
||||||
paramtype = TYPE_UNKNOWN;
|
paramtype = TYPE_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (paramtype == TYPE_STRING && !allow_8bit_chars) {
|
|
||||||
string = PyBytes_AS_STRING(parameter);
|
|
||||||
for (c = string; *c != 0; c++) {
|
|
||||||
if (*c & 0x80) {
|
|
||||||
PyErr_SetString(pysqlite_ProgrammingError, "You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings.");
|
|
||||||
rc = -1;
|
|
||||||
goto final;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (paramtype) {
|
switch (paramtype) {
|
||||||
case TYPE_LONG:
|
case TYPE_LONG:
|
||||||
/* in the overflow error case, longval/longlongval is -1, and an exception is set */
|
/* in the overflow error case, longval/longlongval is -1, and an exception is set */
|
||||||
|
|
Loading…
Reference in New Issue