Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
5a366c3b
Kaydet (Commit)
5a366c3b
authored
May 04, 2008
tarafından
Gerhard Häring
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Applied sqliterow-richcmp.diff patch from Thomas Heller in Issue2152. The
sqlite3.Row type is now correctly hashable.
üst
ffa3357d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
2 deletions
+46
-2
factory.py
Lib/sqlite3/test/factory.py
+20
-0
row.c
Modules/_sqlite/row.c
+26
-2
No files found.
Lib/sqlite3/test/factory.py
Dosyayı görüntüle @
5a366c3b
...
...
@@ -131,6 +131,26 @@ class RowFactoryTests(unittest.TestCase):
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
.
failUnless
(
row_1
==
row_1
)
self
.
failUnless
(
row_1
==
row_2
)
self
.
failUnless
(
row_2
!=
row_3
)
self
.
failIf
(
row_1
!=
row_1
)
self
.
failIf
(
row_1
!=
row_2
)
self
.
failIf
(
row_2
==
row_3
)
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
()
...
...
Modules/_sqlite/row.c
Dosyayı görüntüle @
5a366c3b
...
...
@@ -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 */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment