From c3f22afb19d63bf7bc3f4bde75887f2f236a0187 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Sun, 11 Sep 2016 12:57:15 +0300 Subject: Issue #10740: sqlite3 no longer implicitly commit an open transaction before DDL statements This commit contains the following commits from ghaering/pysqlite: * https://github.com/ghaering/pysqlite/commit/f254c534948c41c0ceb8cbabf0d4a2f547754739 * https://github.com/ghaering/pysqlite/commit/796b3afe38cfdac5d7d5ec260826b0a596554631 * https://github.com/ghaering/pysqlite/commit/cae87ee68613697a5f4947b4a0941f59a28da1b6 * https://github.com/ghaering/pysqlite/commit/3567b31bb5e5b226ba006213a9c69dde3f155faf With the following additions: * Fixed a refcount error * Fixed a compiler warning * Made the string comparison a little more robust * Added a whatsnew entry --- Modules/_sqlite/statement.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'Modules/_sqlite/statement.c') diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c index e87063341d..7b980135ed 100644 --- a/Modules/_sqlite/statement.c +++ b/Modules/_sqlite/statement.c @@ -54,6 +54,7 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con int rc; const char* sql_cstr; Py_ssize_t sql_cstr_len; + const char* p; self->st = NULL; self->in_use = 0; @@ -72,6 +73,23 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con Py_INCREF(sql); self->sql = sql; + /* determine if the statement is a DDL statement */ + self->is_ddl = 0; + for (p = sql_cstr; *p != 0; p++) { + switch (*p) { + case ' ': + case '\r': + case '\n': + case '\t': + continue; + } + + self->is_ddl = (PyOS_strnicmp(p, "create ", 7) == 0) + || (PyOS_strnicmp(p, "drop ", 5) == 0) + || (PyOS_strnicmp(p, "reindex ", 8) == 0); + break; + } + Py_BEGIN_ALLOW_THREADS rc = sqlite3_prepare(connection->db, sql_cstr, -- cgit v1.2.1 From 57c0f2e61c8a5893c37e576a3a03ba5e57c1132c Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 20 Nov 2016 09:13:07 +0200 Subject: Replaced outdated macros _PyUnicode_AsString and _PyUnicode_AsStringAndSize with PyUnicode_AsUTF8 and PyUnicode_AsUTF8AndSize. --- Modules/_sqlite/statement.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Modules/_sqlite/statement.c') diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c index 7b980135ed..0df661b9c7 100644 --- a/Modules/_sqlite/statement.c +++ b/Modules/_sqlite/statement.c @@ -59,7 +59,7 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con self->st = NULL; self->in_use = 0; - sql_cstr = _PyUnicode_AsStringAndSize(sql, &sql_cstr_len); + sql_cstr = PyUnicode_AsUTF8AndSize(sql, &sql_cstr_len); if (sql_cstr == NULL) { rc = PYSQLITE_SQL_WRONG_TYPE; return rc; @@ -152,7 +152,7 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter)); break; case TYPE_UNICODE: - string = _PyUnicode_AsStringAndSize(parameter, &buflen); + string = PyUnicode_AsUTF8AndSize(parameter, &buflen); if (string == NULL) return -1; if (buflen > INT_MAX) { @@ -325,7 +325,7 @@ int pysqlite_statement_recompile(pysqlite_Statement* self, PyObject* params) Py_ssize_t sql_len; sqlite3_stmt* new_st; - sql_cstr = _PyUnicode_AsStringAndSize(self->sql, &sql_len); + sql_cstr = PyUnicode_AsUTF8AndSize(self->sql, &sql_len); if (sql_cstr == NULL) { rc = PYSQLITE_SQL_WRONG_TYPE; return rc; -- cgit v1.2.1