mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
parent
fc3ba6b8fc
commit
023fe334bb
5 changed files with 54 additions and 9 deletions
|
@ -268,9 +268,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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -355,10 +355,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) {
|
||||
|
@ -383,11 +384,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 */
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue