MEMVAR LOOKUP()

From Recital Documentation Wiki
Revision as of 15:08, 27 March 2009 by Yvonnemilne (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

PURPOSE

Lookup a Recital memory variable


SYNONYM

api_memvar_lookup()


SYNOPSIS

#include "dbapi.h"
 
struct API_MEMVAR	MEMVAR_LOOKUP(name)
 
<input parameters>
char	*name;		/* Address of a buffer containing the name of memory variable	*/
 
<output parameters>
none


DESCRIPTION

The MEMVAR_LOOKUP() function will lookup the specified Recital memory variable and return its data type and value into the specified API_MEMVAR data structure.

A NULL value is returned if the memory variable has not previously been defined, otherwise the results are stored in the following API_MEMVAR data structure:

union	API_UNION {
	char			*info_character;		/* Char memory variable		*/
	char			info_logical;		/* Logical memory variable		*/
	double		info_number;		/* Numeric memory variable		*/
	unsigned long	info_date;			/* Date memory variable		*/
	DATETIME		info_datetime;		/* Datetime memory variable		*/
	CURRENCY		info_currency;		/* Currency memory variable		*/
};
 
struct	API_MEMVAR {
	char			type;				/* Data type of memory variable	*/
	union			API_UNION value;	/* Value of the memory variable	*/
	int			width;			/* Display width				*/
	int			decimal;			/* Display # of decimal places		*/
};

The API_MEMVAR type specifies both the data type and which API_UNION value will be used to return the value of the memory variable.

The API_MEMVAR width returns the length of the memory variable. A decimal place may be returned for a number, but will be 0 for other data types.

A memory variable can be defined as any one of the following.


TYPE OUTPUT WIDTH DESCRIPTION
C *info_character 1-8192 Address of a buffer containing a character string
D info_date 8 Unsigned long representing a recital date
L info_logical 1 Character of either 'T' for true or 'F' for false
N info_number 1-16 A value stored in a double
T info_datetime sizeof(DATETIME) RCT_DATETIME_DEF structure
Y info_currency sizeof(CURRENCY) RCT_CURRENCY_DEF structure


EXAMPLE

The following example looks up the memory variable value specified in the first parameter passed and then returns the value as a character string.

#include "dbapi.h"
 
dbapi_memvar_lookup()
{
	struct API_MEMVAR	*result;
	char			buffer[1025];
 
	if (_parinfo(1) != API_CTYPE) _retc("");
 
	result = MEMVAR_LOOKUP(_parc(1));
 
	switch ( result->type )
	{
	case 'C':
		_retc( result->value.info_character );
	case 'D':
		_retc( DATE_DTOS(result->value.info_date));
	case 'N':
		CHAR_STR( buffer,
			result->value.info_number,
			result->width,
			result->decimal);
		_retc( buffer );
	case 'L':
		_retc((result->value.info_logical=='T') ? "True" : "False" );
	}
 
	_retc("");
}


SEE ALSO

ARRAY_LOOKUP(), MEMVAR_DEFINE(), MEMVAR_UPDATE()