diff --git a/src/connection.c b/src/connection.c index 0ba66b2..376502e 100644 --- a/src/connection.c +++ b/src/connection.c @@ -1376,7 +1376,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/src/cursor.c b/src/cursor.c index 2bc1931..69f8a60 100644 --- a/src/cursor.c +++ b/src/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/src/statement.c b/src/statement.c index 7f58b9a..fb1b8bd 100644 --- a/src/statement.c +++ b/src/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; diff --git a/test/dbapi.py b/test/dbapi.py index bdfd496..6249828 100644 --- a/test/dbapi.py +++ b/test/dbapi.py @@ -232,7 +232,7 @@ class CursorTests(unittest.TestCase): """) def CheckExecuteWrongSqlArg(self): - with self.assertRaises(ValueError): + with self.assertRaises(TypeError): self.cu.execute(42) def CheckExecuteArgInt(self): @@ -379,7 +379,7 @@ class CursorTests(unittest.TestCase): 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): diff --git a/test/regression.py b/test/regression.py index d676953..d8aebcc 100644 --- a/test/regression.py +++ b/test/regression.py @@ -262,7 +262,7 @@ class RegressionTests(unittest.TestCase): 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):