Symisc Vedis

An Embeddable Datastore Engine



Vedis C/C++ API Reference - Setting The Result Of a Foreign Command.

Syntax

int vedis_result_int(vedis_context *pCtx,int iValue);

int vedis_result_int64(vedis_context *pCtx,vedis_int64 iValue);

int vedis_result_bool(vedis_context *pCtx,int iBool);

int vedis_result_double(vedis_context *pCtx,double Value);

int vedis_result_null(vedis_context *pCtx);

int vedis_result_string(vedis_context *pCtx,const char *zString,int nLen);

int vedis_result_string_format(vedis_context *pCtx,const char *zFormat,...);

int vedis_result_value(vedis_context *pCtx,vedis_value *pValue);


Set the return value of a foreign command.


Description


These routines are used by the xCmd() callback that implement foreign vedis command to return their computation result. See vedis_register_command() for additional information.


These functions work very much like the vedis_value_* family of functions used to populate vedis values.


The vedis_result_int() interface sets the result from an application-defined command to be an integer value specified by its 2nd argument.


The vedis_result_int64() interface sets the result from an application-defined command to be a 64-bit integer value specified by its 2nd argument.


The vedis_result_double() interface sets the result from an application-defined command to be a floating point value specified by its 2nd argument.


The vedis_result_bool() interface sets the result from an application-defined command to be a Boolean value (Only zero is assumed FALSE) specified by its 2nd argument.


The vedis_result_null() interface sets the return value of the application-defined command to be NULL (default return value).


The vedis_result_value() interface sets the result from an application-defined command to be a copy of the vedis_value obtained by a prior successful call to vedis_context_new_scalar() or vedis_context_new_array(). This is how arrays are returned from foreign commands.


The vedis_result_string() interface sets the result from an application-defined command to be a string value whose content is specified by the 2nd argument.


Note that vedis_result_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_result_string_format() is a work-alike of the "printf()" family of commands from the standard C library which is used to append a formatted string.

Note that the printf() implementation in the vedis core is based on the one found in the SQLite3 source tree.


The vedis_result_string() and vedis_result_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.


Example


vedis_result_string(pCtx,"Welcome, current time is: ",-1);

 vedis_result_string_format(pCtx,"%02d:%02d:%02d",14,12,59);


The final return value of the foreign commands would look like this:


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


If these routines are called from within the different thread than the one containing the application-defined command that received the vedis_context pointer, the results are undefined.


Parameters


pCtx

Call context.


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, Populating Object Values, Obtaining Vedis Object Values, Vedis Object Values Type.



Symisc Systems
Copyright © Symisc Systems