diff options
author | Petri Lehtinen <petri@digip.org> | 2012-02-01 20:20:41 (GMT) |
---|---|---|
committer | Petri Lehtinen <petri@digip.org> | 2012-02-01 20:21:05 (GMT) |
commit | 8940f6242c27fa1c3349503f71903b2b79069994 (patch) | |
tree | e2ee5cec12649eea1830988fab3c02e22beda2be /Modules/_sqlite | |
parent | 590463efc4205337cd231f7bee03e5dabc22063f (diff) | |
parent | 023fe334bbb61fd4912dd6f3e02e19528333ac62 (diff) | |
download | cpython-8940f6242c27fa1c3349503f71903b2b79069994.zip cpython-8940f6242c27fa1c3349503f71903b2b79069994.tar.gz cpython-8940f6242c27fa1c3349503f71903b2b79069994.tar.bz2 |
Merge branch 3.2
Closes #13676.
Diffstat (limited to 'Modules/_sqlite')
-rw-r--r-- | Modules/_sqlite/cursor.c | 13 | ||||
-rw-r--r-- | Modules/_sqlite/statement.c | 4 |
2 files changed, 9 insertions, 8 deletions
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index 75ee73a..99a8612 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -267,9 +267,9 @@ PyObject* _pysqlite_build_column_name(const char* colname) } } -PyObject* pysqlite_unicode_from_string(const char* val_str, int optimize) +PyObject* pysqlite_unicode_from_string(const char* val_str, Py_ssize_t size, int optimize) { - return PyUnicode_FromString(val_str); + return PyUnicode_FromStringAndSize(val_str, size); } /* @@ -354,10 +354,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, + converted = pysqlite_unicode_from_string(val_str, nbytes, self->connection->text_factory == pysqlite_OptimizedUnicode ? 1 : 0); if (!converted) { @@ -382,11 +383,11 @@ 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); + converted = PyObject_CallFunction(self->connection->text_factory, "y#", val_str, nbytes); } } else { /* coltype == SQLITE_BLOB */ 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; |