Update sqlite3 module to match current version of pysqlite.
diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c
index 556ea01..d8d9114 100644
--- a/Modules/_sqlite/statement.c
+++ b/Modules/_sqlite/statement.c
@@ -96,7 +96,7 @@
return rc;
}
-int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter)
+int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter, int allow_8bit_chars)
{
int rc = SQLITE_OK;
long longval;
@@ -108,6 +108,7 @@
Py_ssize_t buflen;
PyObject* stringval;
parameter_type paramtype;
+ char* c;
if (parameter == Py_None) {
rc = sqlite3_bind_null(self->st, pos);
@@ -140,6 +141,17 @@
paramtype = TYPE_UNKNOWN;
}
+ if (paramtype == TYPE_STRING && !allow_8bit_chars) {
+ string = PyString_AS_STRING(parameter);
+ for (c = string; *c != 0; c++) {
+ if (*c & 0x80) {
+ PyErr_SetString(pysqlite_ProgrammingError, "You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings.");
+ rc = -1;
+ goto final;
+ }
+ }
+ }
+
switch (paramtype) {
case TYPE_INT:
longval = PyInt_AsLong(parameter);
@@ -197,7 +209,7 @@
}
}
-void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* parameters)
+void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* parameters, int allow_8bit_chars)
{
PyObject* current_param;
PyObject* adapted;
@@ -251,11 +263,13 @@
}
}
- rc = pysqlite_statement_bind_parameter(self, i + 1, adapted);
+ rc = pysqlite_statement_bind_parameter(self, i + 1, adapted, allow_8bit_chars);
Py_DECREF(adapted);
if (rc != SQLITE_OK) {
- PyErr_Format(pysqlite_InterfaceError, "Error binding parameter %d - probably unsupported type.", i);
+ if (!PyErr_Occurred()) {
+ PyErr_Format(pysqlite_InterfaceError, "Error binding parameter %d - probably unsupported type.", i);
+ }
return;
}
}
@@ -294,11 +308,13 @@
}
}
- rc = pysqlite_statement_bind_parameter(self, i, adapted);
+ rc = pysqlite_statement_bind_parameter(self, i, adapted, allow_8bit_chars);
Py_DECREF(adapted);
if (rc != SQLITE_OK) {
- PyErr_Format(pysqlite_InterfaceError, "Error binding parameter :%s - probably unsupported type.", binding_name);
+ if (!PyErr_Occurred()) {
+ PyErr_Format(pysqlite_InterfaceError, "Error binding parameter :%s - probably unsupported type.", binding_name);
+ }
return;
}
}