diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index 75ee73a..3af0b23 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -267,11 +267,6 @@ PyObject* _pysqlite_build_column_name(const char* colname) } } -PyObject* pysqlite_unicode_from_string(const char* val_str, int optimize) -{ - return PyUnicode_FromString(val_str); -} - /* * Returns a row from the currently active SQLite statement * @@ -354,12 +349,11 @@ PyObject* _pysqlite_fetch_one_row(pysqlite_Cursor* self) converted = PyFloat_FromDouble(sqlite3_column_double(self->statement->st, i)); } else if (coltype == SQLITE_TEXT) { val_str = (const char*)sqlite3_column_text(self->statement->st, i); + nbytes = sqlite3_column_bytes(self->statement->st, i); if ((self->connection->text_factory == (PyObject*)&PyUnicode_Type) || (self->connection->text_factory == pysqlite_OptimizedUnicode)) { - converted = pysqlite_unicode_from_string(val_str, - self->connection->text_factory == pysqlite_OptimizedUnicode ? 1 : 0); - + converted = PyUnicode_FromStringAndSize(val_str, nbytes); if (!converted) { colname = sqlite3_column_name(self->statement->st, i); if (!colname) { @@ -382,9 +376,9 @@ PyObject* _pysqlite_fetch_one_row(pysqlite_Cursor* self) } } } else if (self->connection->text_factory == (PyObject*)&PyBytes_Type) { - converted = PyBytes_FromString(val_str); + converted = PyBytes_FromStringAndSize(val_str, nbytes); } else if (self->connection->text_factory == (PyObject*)&PyByteArray_Type) { - converted = PyByteArray_FromStringAndSize(val_str, strlen(val_str)); + converted = PyByteArray_FromStringAndSize(val_str, nbytes); } else { converted = PyObject_CallFunction(self->connection->text_factory, "y", val_str); } diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c index 4e039c1..cc9c310 100644 --- a/Modules/_sqlite/statement.c +++ b/Modules/_sqlite/statement.c @@ -129,9 +129,9 @@ 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_AsString(parameter); + string = _PyUnicode_AsStringAndSize(parameter, &buflen); if (string != NULL) - rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT); + rc = sqlite3_bind_text(self->st, pos, string, buflen, SQLITE_TRANSIENT); else rc = -1; break;