Index: Lib/sqlite3/test/factory.py =================================================================== --- Lib/sqlite3/test/factory.py (revision 60910) +++ Lib/sqlite3/test/factory.py (working copy) @@ -131,6 +131,17 @@ self.failUnlessEqual(d["a"], row["a"]) self.failUnlessEqual(d["b"], row["b"]) + def CheckSqliteRowHashCmp(self): + """Checks if the row object compares and hashes correctly""" + self.con.row_factory = sqlite.Row + row_1 = self.con.execute("select 1 as a, 2 as b").fetchone() + row_2 = self.con.execute("select 1 as a, 2 as b").fetchone() + row_3 = self.con.execute("select 1 as a, 3 as b").fetchone() + self.failUnlessEqual(row_1, row_2) + self.failUnlessEqual(hash(row_1), hash(row_2)) + self.failIfEqual(row_1, row_3) + self.failIfEqual(hash(row_1), hash(row_3)) + def tearDown(self): self.con.close() Index: Modules/_sqlite/row.c =================================================================== --- Modules/_sqlite/row.c (revision 60910) +++ Modules/_sqlite/row.c (working copy) @@ -169,6 +169,23 @@ return PyObject_GetIter(self->data); } +static long pysqlite_row_hash(pysqlite_Row *self) +{ + return PyObject_Hash(self->description) ^ PyObject_Hash(self->data); +} + +static int pysqlite_row_compare(pysqlite_Row *self, PyObject *_other) +{ + if (PyType_IsSubtype(Py_TYPE(_other), &pysqlite_RowType)) { + pysqlite_Row *other = (pysqlite_Row *)_other; + int res = PyObject_Compare(self->description, other->description); + if (res) + return res; + return PyObject_Compare(self->data, other->data); + } + return -1; +} + PyMappingMethods pysqlite_row_as_mapping = { /* mp_length */ (lenfunc)pysqlite_row_length, /* mp_subscript */ (binaryfunc)pysqlite_row_subscript, @@ -191,12 +208,12 @@ (printfunc)pysqlite_row_print, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_compare */ + pysqlite_row_compare, /* tp_compare */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ - 0, /* tp_hash */ + pysqlite_row_hash, /* tp_hash */ 0, /* tp_call */ 0, /* tp_str */ 0, /* tp_getattro */