Symisc UnQLite

An Embeddable NoSQL Database Engine



UnQLite C/C++ API Reference - JSON Array/Object handling.

Syntax

int unqlite_array_walk(

      unqlite_value *pArray,

      int (*xWalk)(unqlite_value *pKey,unqlite_value *pValue,void *pUserData),

      void *pUserData

);


Iterate over the elements of a given JSON array or object and invoke the supplied callback for each entry.


Description


This routine iterate over the elements of a given array or object and invokes the supplied walker callback for each entry. The first argument (pArray) must be of type array or object obtained by a prior successful call to unqlite_vm_new_array(), unqlite_context_new_array() or passed as parameter to the foreign function. Otherwise, this routine return immediately and the walk process could not be done.


The most interesting parameter is the walker callback which is an user defined function that is invoked for each array or object entry. The callback must accept three arguments. The first argument is the entry key and the second argument is the entry value which could be any type even others JSON arrays and objects and the third and last argument is a copy of the third argument to this function which is forwarded verbatim by engine.

The callback must return UNQLITE_OK. Otherwise the walk process is aborted and this function return UNQLITE_ABORT.


The key and entry value could be extracted inside the callback using these interfaces:


unqlite_value_to_int()

unqlite_value_to_bool()

unqlite_value_to_int64()

unqlite_value_to_double()

unqlite_value_to_string()

unqlite_value_to_resource()

unqlite_value_compare()


Note: The key and its value are passed to the callback by copy. That is, any subsequent changes to their types or values is not reflected. If you want to modify the entry value use unqlite_array_fetch() instead.


Note2: This routine is not thread-safe.

 

Parameters


pArray

unqlite_value to walk which must be of type array or object.

xWalk

Walker callback which is invoked for each array entry. If the callback wishes to abort the walk process, it must return a value different from UNQLITE_OK such as UNQLITE_ABORT.

pUserDara

Arbitrary user pointer which is forwarded verbatim by the engine to the walker callback as its third argument.


Return value


UNQLITE_OK is returned on success. Any other return value indicates failure


Example


Compile this C file for a smart introduction to the JSON array/object handling interfaces.


See also


unqlite_array_add_elem, unqlite_array_count, unqlite_array_fetch.



Symisc Systems
Copyright © Symisc Systems