Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lib/sqlite3/test/dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def CheckExecuteTooMuchSql3(self):
""")

def CheckExecuteWrongSqlArg(self):
with self.assertRaises(ValueError):
with self.assertRaises(TypeError):
self.cu.execute(42)

def CheckExecuteArgInt(self):
Expand Down Expand Up @@ -377,7 +377,7 @@ def mygen():
self.cu.executemany("insert into test(income) values (?)", mygen())

def CheckExecuteManyWrongSqlArg(self):
with self.assertRaises(ValueError):
with self.assertRaises(TypeError):
self.cu.executemany(42, [(3,)])

def CheckExecuteManySelect(self):
Expand Down
2 changes: 1 addition & 1 deletion Lib/sqlite3/test/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def CheckConnectionCall(self):
Call a connection with a non-string SQL request: check error handling
of the statement constructor.
"""
self.assertRaises(sqlite.Warning, self.con, 1)
self.assertRaises(TypeError, self.con, 1)

def CheckCollation(self):
def collation_cb(a, b):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The sqlite3 module now raises TypeError, rather than ValueError, if
operation argument type is not str: execute(), executemany() and calling a
connection.
2 changes: 1 addition & 1 deletion Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 2 additions & 12 deletions Modules/_sqlite/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions Modules/_sqlite/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down