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
be0db8b1
Kaydet (Commit)
be0db8b1
authored
Eki 01, 2003
tarafından
Gregory P. Smith
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bsddb3 4.2.2, adds DBCursor.get_current_size() method to return the length
of the current value without reading the value itself.
üst
efb3a161
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
37 deletions
+71
-37
test_basics.py
Lib/bsddb/test/test_basics.py
+36
-36
_bsddb.c
Modules/_bsddb.c
+35
-1
No files found.
Lib/bsddb/test/test_basics.py
Dosyayı görüntüle @
be0db8b1
...
...
@@ -49,6 +49,8 @@ class BasicTestCase(unittest.TestCase):
envflags
=
0
envsetflags
=
0
_numKeys
=
1002
# PRIVATE. NOTE: must be an even value
def
setUp
(
self
):
if
self
.
useEnv
:
homeDir
=
os
.
path
.
join
(
os
.
path
.
dirname
(
sys
.
argv
[
0
]),
'db_home'
)
...
...
@@ -106,17 +108,23 @@ class BasicTestCase(unittest.TestCase):
def
populateDB
(
self
):
def
populateDB
(
self
,
_txn
=
None
):
d
=
self
.
d
for
x
in
range
(
500
):
key
=
'
%04
d'
%
(
1000
-
x
)
# insert keys in reverse order
for
x
in
range
(
self
.
_numKeys
/
2
):
key
=
'
%04
d'
%
(
self
.
_numKeys
-
x
)
# insert keys in reverse order
data
=
self
.
makeData
(
key
)
d
.
put
(
key
,
data
)
d
.
put
(
key
,
data
,
_txn
)
for
x
in
range
(
500
):
d
.
put
(
'empty value'
,
''
,
_txn
)
for
x
in
range
(
self
.
_numKeys
/
2
-
1
):
key
=
'
%04
d'
%
x
# and now some in forward order
data
=
self
.
makeData
(
key
)
d
.
put
(
key
,
data
)
d
.
put
(
key
,
data
,
_txn
)
if
_txn
:
_txn
.
commit
()
num
=
len
(
d
)
if
verbose
:
...
...
@@ -236,20 +244,20 @@ class BasicTestCase(unittest.TestCase):
if
verbose
:
print
data
assert
len
(
d
)
==
1000
assert
len
(
d
)
==
self
.
_numKeys
keys
=
d
.
keys
()
assert
len
(
keys
)
==
1000
assert
len
(
keys
)
==
self
.
_numKeys
assert
type
(
keys
)
==
type
([])
d
[
'new record'
]
=
'a new record'
assert
len
(
d
)
==
100
1
assert
len
(
d
)
==
self
.
_numKeys
+
1
keys
=
d
.
keys
()
assert
len
(
keys
)
==
100
1
assert
len
(
keys
)
==
self
.
_numKeys
+
1
d
[
'new record'
]
=
'a replacement record'
assert
len
(
d
)
==
100
1
assert
len
(
d
)
==
self
.
_numKeys
+
1
keys
=
d
.
keys
()
assert
len
(
keys
)
==
100
1
assert
len
(
keys
)
==
self
.
_numKeys
+
1
if
verbose
:
print
"the first 10 keys are:"
...
...
@@ -261,7 +269,7 @@ class BasicTestCase(unittest.TestCase):
assert
d
.
has_key
(
'spam'
)
==
0
items
=
d
.
items
()
assert
len
(
items
)
==
100
1
assert
len
(
items
)
==
self
.
_numKeys
+
1
assert
type
(
items
)
==
type
([])
assert
type
(
items
[
0
])
==
type
(())
assert
len
(
items
[
0
])
==
2
...
...
@@ -271,7 +279,7 @@ class BasicTestCase(unittest.TestCase):
pprint
(
items
[:
10
])
values
=
d
.
values
()
assert
len
(
values
)
==
100
1
assert
len
(
values
)
==
self
.
_numKeys
+
1
assert
type
(
values
)
==
type
([])
if
verbose
:
...
...
@@ -293,7 +301,7 @@ class BasicTestCase(unittest.TestCase):
else
:
txn
=
None
c
=
self
.
d
.
cursor
(
txn
=
txn
)
rec
=
c
.
first
()
count
=
0
while
rec
is
not
None
:
...
...
@@ -309,8 +317,9 @@ class BasicTestCase(unittest.TestCase):
rec
=
None
else
:
self
.
fail
(
"unexpected DBNotFoundError"
)
assert
count
==
1000
assert
c
.
get_current_size
()
==
len
(
c
.
current
()[
1
]),
"
%
s != len(
%
r)"
%
(
c
.
get_current_size
(),
c
.
current
()[
1
])
assert
count
==
self
.
_numKeys
rec
=
c
.
last
()
...
...
@@ -329,14 +338,20 @@ class BasicTestCase(unittest.TestCase):
else
:
self
.
fail
(
"unexpected DBNotFoundError"
)
assert
count
==
1000
assert
count
==
self
.
_numKeys
rec
=
c
.
set
(
'0505'
)
rec2
=
c
.
current
()
assert
rec
==
rec2
assert
rec
[
0
]
==
'0505'
assert
rec
[
1
]
==
self
.
makeData
(
'0505'
)
assert
c
.
get_current_size
()
==
len
(
rec
[
1
])
# make sure we get empty values properly
rec
=
c
.
set
(
'empty value'
)
assert
rec
[
1
]
==
''
assert
c
.
get_current_size
()
==
0
try
:
n
=
c
.
set
(
'bad key'
)
except
db
.
DBNotFoundError
,
val
:
...
...
@@ -575,23 +590,8 @@ class BasicTransactionTestCase(BasicTestCase):
def
populateDB
(
self
):
d
=
self
.
d
txn
=
self
.
env
.
txn_begin
()
for
x
in
range
(
500
):
key
=
'
%04
d'
%
(
1000
-
x
)
# insert keys in reverse order
data
=
self
.
makeData
(
key
)
d
.
put
(
key
,
data
,
txn
)
for
x
in
range
(
500
):
key
=
'
%04
d'
%
x
# and now some in forward order
data
=
self
.
makeData
(
key
)
d
.
put
(
key
,
data
,
txn
)
txn
.
commit
()
num
=
len
(
d
)
if
verbose
:
print
"created
%
d records"
%
num
BasicTestCase
.
populateDB
(
self
,
_txn
=
txn
)
self
.
txn
=
self
.
env
.
txn_begin
()
...
...
@@ -626,7 +626,7 @@ class BasicTransactionTestCase(BasicTestCase):
if
verbose
and
count
%
100
==
0
:
print
rec
rec
=
c
.
next
()
assert
count
==
100
1
assert
count
==
self
.
_numKeys
+
1
c
.
close
()
# Cursors *MUST* be closed before commit!
self
.
txn
.
commit
()
...
...
@@ -855,7 +855,7 @@ class BasicMultiDBTestCase(BasicTestCase):
if
verbose
and
(
count
%
50
)
==
0
:
print
rec
rec
=
c1
.
next
()
assert
count
==
1000
assert
count
==
self
.
_numKeys
count
=
0
rec
=
c2
.
first
()
...
...
Modules/_bsddb.c
Dosyayı görüntüle @
be0db8b1
...
...
@@ -93,7 +93,7 @@
/* 40 = 4.0, 33 = 3.3; this will break if the second number is > 9 */
#define DBVER (DB_VERSION_MAJOR * 10 + DB_VERSION_MINOR)
#define PY_BSDDB_VERSION "4.2.
1
"
#define PY_BSDDB_VERSION "4.2.
2
"
static
char
*
rcs_id
=
"$Id$"
;
...
...
@@ -2981,6 +2981,39 @@ DBC_get_both(DBCursorObject* self, PyObject* args)
self
->
mydb
->
moduleFlags
.
getReturnsNone
);
}
/* Return size of entry */
static
PyObject
*
DBC_get_current_size
(
DBCursorObject
*
self
,
PyObject
*
args
)
{
int
err
,
flags
=
DB_CURRENT
;
PyObject
*
retval
=
NULL
;
DBT
key
,
data
;
if
(
!
PyArg_ParseTuple
(
args
,
":get_current_size"
))
return
NULL
;
CHECK_CURSOR_NOT_CLOSED
(
self
);
CLEAR_DBT
(
key
);
CLEAR_DBT
(
data
);
/* We don't allocate any memory, forcing a ENOMEM error and thus
getting the record size. */
data
.
flags
=
DB_DBT_USERMEM
;
data
.
ulen
=
0
;
MYDB_BEGIN_ALLOW_THREADS
;
err
=
self
->
dbc
->
c_get
(
self
->
dbc
,
&
key
,
&
data
,
flags
);
MYDB_END_ALLOW_THREADS
;
if
(
err
==
ENOMEM
||
!
err
)
{
/* ENOMEM means positive size, !err means zero length value */
retval
=
PyInt_FromLong
((
long
)
data
.
size
);
err
=
0
;
}
FREE_DBT
(
key
);
FREE_DBT
(
data
);
RETURN_IF_ERR
();
return
retval
;
}
static
PyObject
*
DBC_set_both
(
DBCursorObject
*
self
,
PyObject
*
args
)
{
...
...
@@ -4079,6 +4112,7 @@ static PyMethodDef DBCursor_methods[] = {
{
"set"
,
(
PyCFunction
)
DBC_set
,
METH_VARARGS
|
METH_KEYWORDS
},
{
"set_range"
,
(
PyCFunction
)
DBC_set_range
,
METH_VARARGS
|
METH_KEYWORDS
},
{
"get_both"
,
(
PyCFunction
)
DBC_get_both
,
METH_VARARGS
},
{
"get_current_size"
,(
PyCFunction
)
DBC_get_current_size
,
METH_VARARGS
},
{
"set_both"
,
(
PyCFunction
)
DBC_set_both
,
METH_VARARGS
},
{
"set_recno"
,
(
PyCFunction
)
DBC_set_recno
,
METH_VARARGS
|
METH_KEYWORDS
},
{
"consume"
,
(
PyCFunction
)
DBC_consume
,
METH_VARARGS
|
METH_KEYWORDS
},
...
...
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