Symisc Vedis

An Embeddable Datastore Engine



Vedis C/C++ API Reference - Populating Dynamically Typed Objects.

Syntax

int vedis_value_int(vedis_value *pVal,int iValue);

int vedis_value_int64(vedis_value *pVal,vedis_int64 iValue);

int vedis_value_bool(vedis_value *pVal,int iBool);

int vedis_value_null(vedis_value *pVal);

int vedis_value_double(vedis_value *pVal,double Value);

int vedis_value_string(vedis_value *pVal,const char *zString,int nLen);

int vedis_value_string_format(vedis_value *pVal,const char *zFormat,...);

int vedis_value_reset_string_cursor(vedis_value *pVal);


Populate a Vedis object value.


Description


These routines are used to populate a freshly created vedis object value obtained by a prior successful call to vedis_context_new_scalar() or  vedis_context_new_scalar().


The vedis_value_int() interface sets the vedis_value to the integer type where the value is specified by its 2nd argument.


The vedis_value_int64() interface sets the vedis_value to the 64-bit integer type where the value is specified by its 2nd argument.


The vedis_value_double() interface sets the vedis_value to the double type where the value is specified by its 2nd argument.


The vedis_value_bool() interface sets the vedis_value to the boolean type where the value (Only zero is assumed to be FALSE) is specified by its 2nd argument.


The vedis_value_null() interface sets the vedis_value to the NULL type.


The vedis_value_string() interface sets the vedis_value to the string type where the string content is specified by the 2nd argument.

Note that vedis_value_string() accepts a third argument which is the length of the string to append. If the nLen argument is less than zero, then zString is read up to the first zero terminator. If nLen is non-negative, then it is the maximum number of bytes read from zString.


vedis_value_string_format() is a work-alike of the "printf()" family of functions from the standard C library which is used to append a formatted string.


The vedis_value_string() and vedis_value_string_format() interfaces write their result to an internal buffer which grow automatically by successive calls to one of them (An append operation). That is, previously written data is not erased by the new call. If such behavior is wanted, call vedis_value_reset_string_cursor() to reset the internal buffer.


Example


vedis_value_string(pValue,"Welcome, current time is: ",-1);

         vedis_value_string_format(pValue,"%02d:%02d:%02d",14,12,59);


The final result if extracted by vedis_value_to_string() would look like this:


Welcome, current time is: 14:12:59”


These routines are very useful when implementing foreign commands which works with arrays.


Note: If these routines are called from within the different thread than the one containing the application-defined function that received the vedis_value pointer, the results are undefined.


Parameters


pVal

A pointer to a vedis_value to be populated.


Return value


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


Example


Compile this C file for a smart introduction to these interfaces.


See also


On Demand Object Allocation, Setting the Result of a Foreign Command, Obtaining Vedis Object Values, Vedis Object Values Type.



Symisc Systems
Copyright © Symisc Systems