mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
follow in a few hours at the latest. Then we should be ready for beta1.
This commit is contained in:
parent
ea3912b0da
commit
1541ef08af
7 changed files with 376 additions and 96 deletions
|
|
@ -137,6 +137,22 @@ void cursor_dealloc(Cursor* self)
|
|||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
PyObject* _get_converter(PyObject* key)
|
||||
{
|
||||
PyObject* upcase_key;
|
||||
PyObject* retval;
|
||||
|
||||
upcase_key = PyObject_CallMethod(key, "upper", "");
|
||||
if (!upcase_key) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
retval = PyDict_GetItem(converters, upcase_key);
|
||||
Py_DECREF(upcase_key);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
int build_row_cast_map(Cursor* self)
|
||||
{
|
||||
int i;
|
||||
|
|
@ -174,7 +190,7 @@ int build_row_cast_map(Cursor* self)
|
|||
break;
|
||||
}
|
||||
|
||||
converter = PyDict_GetItem(converters, key);
|
||||
converter = _get_converter(key);
|
||||
Py_DECREF(key);
|
||||
break;
|
||||
}
|
||||
|
|
@ -195,7 +211,7 @@ int build_row_cast_map(Cursor* self)
|
|||
}
|
||||
}
|
||||
|
||||
converter = PyDict_GetItem(converters, py_decltype);
|
||||
converter = _get_converter(py_decltype);
|
||||
Py_DECREF(py_decltype);
|
||||
}
|
||||
}
|
||||
|
|
@ -228,7 +244,10 @@ PyObject* _build_column_name(const char* colname)
|
|||
}
|
||||
|
||||
for (pos = colname;; pos++) {
|
||||
if (*pos == 0 || *pos == ' ') {
|
||||
if (*pos == 0 || *pos == '[') {
|
||||
if ((*pos == '[') && (pos > colname) && (*(pos-1) == ' ')) {
|
||||
pos--;
|
||||
}
|
||||
return PyString_FromStringAndSize(colname, pos - colname);
|
||||
}
|
||||
}
|
||||
|
|
@ -312,13 +331,10 @@ PyObject* _fetch_one_row(Cursor* self)
|
|||
return NULL;
|
||||
}
|
||||
converted = PyObject_CallFunction(converter, "O", item);
|
||||
if (!converted) {
|
||||
/* TODO: have a way to log these errors */
|
||||
Py_INCREF(Py_None);
|
||||
converted = Py_None;
|
||||
PyErr_Clear();
|
||||
}
|
||||
Py_DECREF(item);
|
||||
if (!converted) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
|
|
@ -346,10 +362,10 @@ PyObject* _fetch_one_row(Cursor* self)
|
|||
|
||||
if (!converted) {
|
||||
colname = sqlite3_column_name(self->statement->st, i);
|
||||
if (colname) {
|
||||
if (!colname) {
|
||||
colname = "<unknown column name>";
|
||||
}
|
||||
PyOS_snprintf(buf, sizeof(buf) - 1, "Could not decode to UTF-8 column %s with text %s",
|
||||
PyOS_snprintf(buf, sizeof(buf) - 1, "Could not decode to UTF-8 column '%s' with text '%s'",
|
||||
colname , val_str);
|
||||
PyErr_SetString(OperationalError, buf);
|
||||
}
|
||||
|
|
@ -373,7 +389,12 @@ PyObject* _fetch_one_row(Cursor* self)
|
|||
}
|
||||
}
|
||||
|
||||
PyTuple_SetItem(row, i, converted);
|
||||
if (converted) {
|
||||
PyTuple_SetItem(row, i, converted);
|
||||
} else {
|
||||
Py_INCREF(Py_None);
|
||||
PyTuple_SetItem(row, i, Py_None);
|
||||
}
|
||||
}
|
||||
|
||||
if (PyErr_Occurred()) {
|
||||
|
|
@ -598,6 +619,14 @@ PyObject* _query_execute(Cursor* self, int multiple, PyObject* args)
|
|||
goto error;
|
||||
}
|
||||
} else {
|
||||
if (PyErr_Occurred()) {
|
||||
/* there was an error that occured in a user-defined callback */
|
||||
if (_enable_callback_tracebacks) {
|
||||
PyErr_Print();
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
}
|
||||
_seterror(self->connection->db);
|
||||
goto error;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue