Brian, thanks for your help with my previous question!
I have another one. Let's say I defined a hashed view keyed on the
first 3 columns. I cannot seem to be able to use find() to locate a
row afterwards. Consider the following code:
import metakit.metakit as mk
def test_find ():
st = mk.storage()
vw = st.getas( "test[k1:I,k2:I,k3:I,val:I]" )
for x in xrange(4):
for y in xrange(3):
for z in xrange(2):
val = x*100 + y*10 + z
vw.append( k1=x, k2=y, k3=z, val=val )
hvw = st.getas( "testhash[_H:I,_R:I]" )
vw = vw.hash( hvw, 3 )
for i, row in enumerate(vw):
print 'row=%d : key=(%d, %d, %d) : val=%d' % (i, row.k1, row.k2,
row.k3, row.val)
i = vw.find( k1=2, k2=1, k3=1)
###i = vw.find( {'k1':2, 'k2':1, 'k3':1} )
print 'find() got idx: ', i
v2 = vw.select( k1=2, k2=1, k3=1 )
mk.dump(v2)
if __name__ == '__main__':
test_find()
I got the following output:
row=0 : key=(0, 0, 0) : val=0
row=1 : key=(0, 0, 1) : val=1
row=2 : key=(0, 1, 0) : val=10
row=3 : key=(0, 1, 1) : val=11
row=4 : key=(0, 2, 0) : val=20
row=5 : key=(0, 2, 1) : val=21
row=6 : key=(1, 0, 0) : val=100
row=7 : key=(1, 0, 1) : val=101
row=8 : key=(1, 1, 0) : val=110
row=9 : key=(1, 1, 1) : val=111
row=10 : key=(1, 2, 0) : val=120
row=11 : key=(1, 2, 1) : val=121
row=12 : key=(2, 0, 0) : val=200
row=13 : key=(2, 0, 1) : val=201
row=14 : key=(2, 1, 0) : val=210
row=15 : key=(2, 1, 1) : val=211
row=16 : key=(2, 2, 0) : val=220
row=17 : key=(2, 2, 1) : val=221
row=18 : key=(3, 0, 0) : val=300
row=19 : key=(3, 0, 1) : val=301
row=20 : key=(3, 1, 0) : val=310
row=21 : key=(3, 1, 1) : val=311
row=22 : key=(3, 2, 0) : val=320
row=23 : key=(3, 2, 1) : val=321
find() got idx: -1
k1 k2 k3 val
-- -- -- ---
2 1 1 211
-- -- -- ---
Total: 1 rows
So the select() worked but not the find(). What am I doing wrong with
find()?
I'm using Active Python v2.3.2 on Win XP.
--
Cheers,
David
_____________________________________________
Metakit mailing list - [EMAIL PROTECTED]
http://www.equi4.com/mailman/listinfo/metakit