Mercurial > cpython-lru_cache-weakref
diff Modules/_sqlite/statement.c @ 46166:a21854e510b4 legacy-trunk
Update sqlite3 module to match current version of pysqlite.
| author | Gerhard Häring <gh@ghaering.de> |
|---|---|
| date | Fri, 28 Mar 2008 20:08:36 +0000 |
| parents | b7ee9074ca0e |
| children | 6db392ac9f4e |
line wrap: on
line diff
--- a/Modules/_sqlite/statement.c Fri Mar 28 12:58:26 2008 +0000 +++ b/Modules/_sqlite/statement.c Fri Mar 28 20:08:36 2008 +0000 @@ -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; } }
