diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-06-26 01:16:24 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-26 01:16:24 (GMT) |
commit | c6a2320e876354ee62cf8149b849bcff9492d38a (patch) | |
tree | d5f5042334eb149bf08a01e7f09b429db0360ff2 /Modules | |
parent | ed076ed467264b43ed01a8223ca65b133b590919 (diff) | |
download | cpython-c6a2320e876354ee62cf8149b849bcff9492d38a.zip cpython-c6a2320e876354ee62cf8149b849bcff9492d38a.tar.gz cpython-c6a2320e876354ee62cf8149b849bcff9492d38a.tar.bz2 |
bpo-37406: sqlite3 raises TypeError for wrong operation type (GH-14386)
The sqlite3 module now raises TypeError, rather than ValueError, if
operation argument type is not str: execute(), executemany() and
calling a connection.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_sqlite/connection.c | 2 | ||||
-rw-r--r-- | Modules/_sqlite/cursor.c | 14 | ||||
-rw-r--r-- | Modules/_sqlite/statement.c | 2 |
3 files changed, 5 insertions, 13 deletions
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index 0d6462e..5ceeaf9 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -1223,7 +1223,7 @@ PyObject* pysqlite_connection_call(pysqlite_Connection* self, PyObject* args, Py if (!_PyArg_NoKeywords(MODULE_NAME ".Connection", kwargs)) return NULL; - if (!PyArg_ParseTuple(args, "O", &sql)) + if (!PyArg_ParseTuple(args, "U", &sql)) return NULL; _pysqlite_drop_unused_statement_references(self); diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index 01b9dc4..38d94b2 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -384,12 +384,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* args) if (multiple) { /* executemany() */ - if (!PyArg_ParseTuple(args, "OO", &operation, &second_argument)) { - goto error; - } - - if (!PyUnicode_Check(operation)) { - PyErr_SetString(PyExc_ValueError, "operation parameter must be str"); + if (!PyArg_ParseTuple(args, "UO", &operation, &second_argument)) { goto error; } @@ -406,12 +401,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* args) } } else { /* execute() */ - if (!PyArg_ParseTuple(args, "O|O", &operation, &second_argument)) { - goto error; - } - - if (!PyUnicode_Check(operation)) { - PyErr_SetString(PyExc_ValueError, "operation parameter must be str"); + if (!PyArg_ParseTuple(args, "U|O", &operation, &second_argument)) { goto error; } diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c index 491294b..9de8f9b 100644 --- a/Modules/_sqlite/statement.c +++ b/Modules/_sqlite/statement.c @@ -59,6 +59,8 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con self->st = NULL; self->in_use = 0; + assert(PyUnicode_Check(sql)); + sql_cstr = PyUnicode_AsUTF8AndSize(sql, &sql_cstr_len); if (sql_cstr == NULL) { rc = PYSQLITE_SQL_WRONG_TYPE; |