Symisc UnQLite

An Embeddable NoSQL Database Engine



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

Syntax

int unqlite_array_add_elem(unqlite_value *pArray,unqlite_value *pKey,unqlite_value *pValue);

int unqlite_array_add_strkey_elem(unqlite_value *pArray,const char *zKey,unqlite_value *pValue);


Populate a JSON array or a JSON object.


Description


These routines are used to populate a JSON array or object with the desired record (Field for a JSON object). The given unqlite_value (first argument) must be of type array or object obtained by a prior successful call to unqlite_vm_new_array() or unqlite_context_new_array(). Otherwise these routines return immediately with an error code.


The second argument to unqlite_array_add_elem() is a scalar unqlite_value obtained by a prior successful call to unqlite_vm_new_scalar(), unqlite_context_new_array() or passed as parameter to the foreign function. Note that if you want an automatically assigned key (usually a numeric number), simply pass NULL.


The third argument to unqlite_array_add_elem() is a unqlite_value of any type obtained by a prior successful call unqlite_vm_new_scalar(), unqlite_context_new_scalar(), unqlite_vm_new_array(), unqlite_context_new_array() or passed as parameter to the foreign function.

This is the record value which could be extracted later using unqlite_array_fetch() or from your Jx9 code using the standard array/object access operators (i.e: $array['key'] or $obj.field). Note that if you want a null entry value, simply pass NULL.


unqlite_array_add_strkey_elem() is a simple wrapper around unqlite_array_add_elem() where its key is a pointer to a null terminated string


Note: These routines make their own copy of the given key, value pair so it is safe to use the same unqlite_value for other insertions.


Note2: These routines are not thread-safe.

 

Parameters


pArray

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


Return value


UNQLITE_OK is returned on successful insertion. Any other return value typically (UNQLITE_CORRUPT or UNQLITE_NOMEM) indicates failure.


Example


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


See also


unqlite_array_walk, unqlite_array_count, unqlite_array_fetch.



Symisc Systems
Copyright © Symisc Systems