summaryrefslogtreecommitdiffstats
path: root/Modules/_sqlite/row.c
diff options
context:
space:
mode:
authorGerhard Häring <gh@ghaering.de>2008-05-04 13:15:12 (GMT)
committerGerhard Häring <gh@ghaering.de>2008-05-04 13:15:12 (GMT)
commit5a366c3b8bf1e8afb2d48a02b498f2eaab812c49 (patch)
tree39166c3187d413d0e11378568b35dc0e430c8981 /Modules/_sqlite/row.c
parentffa3357d5227ff746ba243fa5cd720f397ac7bec (diff)
downloadcpython-5a366c3b8bf1e8afb2d48a02b498f2eaab812c49.zip
cpython-5a366c3b8bf1e8afb2d48a02b498f2eaab812c49.tar.gz
cpython-5a366c3b8bf1e8afb2d48a02b498f2eaab812c49.tar.bz2
Applied sqliterow-richcmp.diff patch from Thomas Heller in Issue2152. The
sqlite3.Row type is now correctly hashable.
Diffstat (limited to 'Modules/_sqlite/row.c')
-rw-r--r--Modules/_sqlite/row.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/Modules/_sqlite/row.c b/Modules/_sqlite/row.c
index 8f155d9..3419267 100644
--- a/Modules/_sqlite/row.c
+++ b/Modules/_sqlite/row.c
@@ -169,6 +169,30 @@ static PyObject* pysqlite_iter(pysqlite_Row* self)
return PyObject_GetIter(self->data);
}
+static long pysqlite_row_hash(pysqlite_Row *self)
+{
+ return PyObject_Hash(self->description) ^ PyObject_Hash(self->data);
+}
+
+static PyObject* pysqlite_row_richcompare(pysqlite_Row *self, PyObject *_other, int opid)
+{
+ if (opid != Py_EQ && opid != Py_NE) {
+ Py_INCREF(Py_NotImplemented);
+ return Py_NotImplemented;
+ }
+ if (PyType_IsSubtype(Py_TYPE(_other), &pysqlite_RowType)) {
+ pysqlite_Row *other = (pysqlite_Row *)_other;
+ PyObject *res = PyObject_RichCompare(self->description, other->description, opid);
+ if (opid == Py_EQ && res == Py_True
+ || opid == Py_NE && res == Py_False) {
+ Py_DECREF(res);
+ return PyObject_RichCompare(self->data, other->data, opid);
+ }
+ }
+ Py_INCREF(Py_NotImplemented);
+ return Py_NotImplemented;
+}
+
PyMappingMethods pysqlite_row_as_mapping = {
/* mp_length */ (lenfunc)pysqlite_row_length,
/* mp_subscript */ (binaryfunc)pysqlite_row_subscript,
@@ -196,7 +220,7 @@ PyTypeObject pysqlite_RowType = {
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
- 0, /* tp_hash */
+ (hashfunc)pysqlite_row_hash, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
@@ -206,7 +230,7 @@ PyTypeObject pysqlite_RowType = {
0, /* tp_doc */
(traverseproc)0, /* tp_traverse */
0, /* tp_clear */
- 0, /* tp_richcompare */
+ (richcmpfunc)pysqlite_row_richcompare, /* tp_richcompare */
0, /* tp_weaklistoffset */
(getiterfunc)pysqlite_iter, /* tp_iter */
0, /* tp_iternext */