summaryrefslogtreecommitdiff
path: root/Modules/_sqlite/statement.c
diff options
context:
space:
mode:
authorMariatta Wijaya <mariatta.wijaya@gmail.com>2017-02-06 20:16:58 -0800
committerMariatta Wijaya <mariatta.wijaya@gmail.com>2017-02-06 20:16:58 -0800
commitda79bcf8ac7ae72218ab023e1ed54390bc1a3a27 (patch)
tree74845e2dbd9521d9748b9c32f1922f4123083bf3 /Modules/_sqlite/statement.c
parente3c7e835bdfc97750eb9b7fc0ad2493108c2d438 (diff)
parent1fe806ac56f8b83694d24ab604eb695d00bc8497 (diff)
downloadcpython-da79bcf8ac7ae72218ab023e1ed54390bc1a3a27.tar.gz
Issue #29371: merge with 3.5
Diffstat (limited to 'Modules/_sqlite/statement.c')
-rw-r--r--Modules/_sqlite/statement.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c
index e87063341d..0df661b9c7 100644
--- a/Modules/_sqlite/statement.c
+++ b/Modules/_sqlite/statement.c
@@ -54,11 +54,12 @@ 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;
- 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;
@@ -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,
@@ -134,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) {
@@ -307,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;