summaryrefslogtreecommitdiffstats
path: root/Modules/_sqlite/cursor.c
diff options
context:
space:
mode:
authorGerhard Häring <gh@ghaering.de>2006-06-13 22:24:47 (GMT)
committerGerhard Häring <gh@ghaering.de>2006-06-13 22:24:47 (GMT)
commit1541ef08afda1da09ec99cfb5305fdc0af04ef40 (patch)
tree5ece2f7b0508920b06f4f6c001066418c483cb87 /Modules/_sqlite/cursor.c
parentea3912b0da71e16b8a37e04fcf3969dc85c27fa1 (diff)
downloadcpython-1541ef08afda1da09ec99cfb5305fdc0af04ef40.zip
cpython-1541ef08afda1da09ec99cfb5305fdc0af04ef40.tar.gz
cpython-1541ef08afda1da09ec99cfb5305fdc0af04ef40.tar.bz2
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.
Diffstat (limited to 'Modules/_sqlite/cursor.c')
-rw-r--r--Modules/_sqlite/cursor.c51
1 files changed, 40 insertions, 11 deletions
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
index 6ee8bea..98f5e0d 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -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);
+ Py_DECREF(item);
if (!converted) {
- /* TODO: have a way to log these errors */
- Py_INCREF(Py_None);
- converted = Py_None;
- PyErr_Clear();
+ break;
}
- Py_DECREF(item);
}
} 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;
}