I'm using nobonobo's python bindings to unqlite and am running into an issue when attempting to work with a JSON document collection.
In the README, there is this JX9 script:
sample = (
"db_create('users'); /* Create the collection users */"
"db_store('users',{ 'name' : 'dean' , 'age' : 32 });"
"db_store('users',{ 'name' : 'chems' , 'age' : 27 });"
"print db_fetch_all('users')..'\n';"
"while( ($rec = db_fetch('users')) != NULL ){"
" print $rec; print '\n';"
"}"
)
This correctly prints each record:
[{"name":"dean","age":32,"__id":0},{"name":"chems","age":27,"__id":1}]
{"name":"dean","age":32,"__id":0}
{"name":"chems","age":27,"__id":1}
However when I try to read the collection in Python using a callback, I get garbage back:
@unqlitepy.OutputCallback
def f(output, outlen, udata):
output = (c_char*outlen).from_address(output).raw
print locals()
return unqlitepy.UNQLITE_OK
db.fetch_cb('users', f)
This is the output:
{'udata': None, 'output': 'a\x1e\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x02D\xa7\x83\x0b', 'outlen': 22L}
Similarly if I grab a cursor and print the first user in the users collection, I get this:
'users_0' '\x01\x08\x00\x00\x00\x04name\x05\x08\x00\x00\x00\x04dean\x06\x08\x00\x00\x00\x03age\x05\n\x00\x00\x00\x00\x00\x00\x00 \x06\x08\x00\x00\x00\x04__id\x05\n\x00\x00\x00\x00\x00\x00\x00\x00\x06\x02'
Does anybody know what might be happening? Is there some way to decode the data returned to python?