src/pl/tcl/pltcl.c
static void
pltcl_set_tuple_values(Tcl_Interp *interp, const char *arrayname,
					   uint64 tupno, HeapTuple tuple, TupleDesc tupdesc)
{
	int			i;
	char	   *outputstr;
	Datum		attr;
	bool		isnull;
	const char *attname;
	Oid			typoutput;
	bool		typisvarlena;
	const char **arrptr;
	const char **nameptr;
	const char *nullname = NULL;

	/************************************************************
	 * Prepare pointers for Tcl_SetVar2Ex() below
	 ************************************************************/
	if (arrayname == NULL)
	{
		arrptr = &attname;
		nameptr = &nullname;
	}
	else
	{
		arrptr = &arrayname;
		nameptr = &attname;

		/*
		 * When outputting to an array, fill the ".tupno" element with the
		 * current tuple number.  This will be overridden below if ".tupno" is
		 * in use as an actual field name in the rowtype.
		 */
		Tcl_SetVar2Ex(interp, arrayname, ".tupno", Tcl_NewWideIntObj(tupno), 0);
	}

	for (i = 0; i < tupdesc->natts; i++)
	{
		Form_pg_attribute att = TupleDescAttr(tupdesc, i);

		/* ignore dropped attributes */
		if (att->attisdropped)
			continue;

		/************************************************************
		 * Get the attribute name
		 ************************************************************/
		UTF_BEGIN;
		attname = pstrdup(UTF_E2U(NameStr(att->attname)));
		UTF_END;

		/************************************************************
		 * Get the attributes value
		 ************************************************************/
		attr = heap_getattr(tuple, i + 1, tupdesc, &isnull);

		/************************************************************
		 * If there is a value, set the variable
		 * If not, unset it
		 *
		 * Hmmm - Null attributes will cause functions to
		 *		  crash if they don't expect them - need something
		 *		  smarter here.
		 ************************************************************/
		if (!isnull)
		{
			getTypeOutputInfo(att->atttypid, &typoutput, &typisvarlena);
			outputstr = OidOutputFunctionCall(typoutput, attr);
			UTF_BEGIN;
			Tcl_SetVar2Ex(interp, *arrptr, *nameptr,
						  Tcl_NewStringObj(UTF_E2U(outputstr), -1), 0);
			UTF_END;
			pfree(outputstr);
		}
		else
			Tcl_UnsetVar2(interp, *arrptr, *nameptr, 0);

		pfree(unconstify(char *, attname));
	}
}
/**********************************************************************
 * pltcl_set_tuple_values() - Set variables for all attributes
 *				  of a given tuple
 *
 * Note: arrayname is presumed to be UTF8; it usually came from Tcl
 **********************************************************************/
Set variables for all attributes
of a given tuple

arrayname is presumed to be UTF8; it usually came from Tcl
Set variables for all attributes of a given tuple arrayname is presumed to be UTF8 ; it usually came from Tcl
static void
pltcl_set_tuple_values(Tcl_Interp *interp, const char *arrayname,
					   uint64 tupno, HeapTuple tuple, TupleDesc tupdesc)
{
	int			i;
	char	   *outputstr;
	Datum		attr;
	bool		isnull;
	const char *attname;
	Oid			typoutput;
	bool		typisvarlena;
	const char **arrptr;
	const char **nameptr;
	const char *nullname = NULL;
	if (arrayname == NULL)
	{
		arrptr = &attname;
		nameptr = &nullname;
	}
	else
	{
		arrptr = &arrayname;
		nameptr = &attname;
		Tcl_SetVar2Ex(interp, arrayname, ".tupno", Tcl_NewWideIntObj(tupno), 0);
	}
	for (i = 0; i < tupdesc->natts; i++)
	{
		Form_pg_attribute att = TupleDescAttr(tupdesc, i);
		if (att->attisdropped)
			continue;
		UTF_BEGIN;
		attname = pstrdup(UTF_E2U(NameStr(att->attname)));
		UTF_END;
		attr = heap_getattr(tuple, i + 1, tupdesc, &isnull);
		if (!isnull)
		{
			getTypeOutputInfo(att->atttypid, &typoutput, &typisvarlena);
			outputstr = OidOutputFunctionCall(typoutput, attr);
			UTF_BEGIN;
			Tcl_SetVar2Ex(interp, *arrptr, *nameptr,
						  Tcl_NewStringObj(UTF_E2U(outputstr), -1), 0);
			UTF_END;
			pfree(outputstr);
		}
		else
			Tcl_UnsetVar2(interp, *arrptr, *nameptr, 0);
		pfree(unconstify(char *, attname));
	}
}
static void pltcl_set_tuple_values ( Tcl_Interp * interp , const char * arrayname , uint64 tupno , HeapTuple tuple , TupleDesc tupdesc ) { int i ; char * outputstr ; Datum attr ; bool isnull ; const char * attname ; Oid typoutput ; bool typisvarlena ; const char * * arrptr ; const char * * nameptr ; const char * nullname = NULL ; if ( arrayname == NULL ) { arrptr = & attname ; nameptr = & nullname ; } else { arrptr = & arrayname ; nameptr = & attname ; Tcl_SetVar2Ex ( interp , arrayname , " " , Tcl_NewWideIntObj ( tupno ) , 0 ) ; } for ( i = 0 ; i < tupdesc -> natts ; i ++ ) { Form_pg_attribute att = TupleDescAttr ( tupdesc , i ) ; if ( att -> attisdropped ) continue ; UTF_BEGIN ; attname = pstrdup ( UTF_E2U ( NameStr ( att -> attname ) ) ) ; UTF_END ; attr = heap_getattr ( tuple , i + 1 , tupdesc , & isnull ) ; if ( ! isnull ) { getTypeOutputInfo ( att -> atttypid , & typoutput , & typisvarlena ) ; outputstr = OidOutputFunctionCall ( typoutput , attr ) ; UTF_BEGIN ; Tcl_SetVar2Ex ( interp , * arrptr , * nameptr , Tcl_NewStringObj ( UTF_E2U ( outputstr ) , -1 ) , 0 ) ; UTF_END ; pfree ( outputstr ) ; } else Tcl_UnsetVar2 ( interp , * arrptr , * nameptr , 0 ) ; pfree ( unconstify ( char * , attname ) ) ; } }
pltcl_set_tuple_values() - Set variables for all attributes
                                of a given tuple
pltcl_set_tuple_values () - Set variables for all attributes of a given tuple
/************************************************************
	 * Prepare pointers for Tcl_SetVar2Ex() below
	 ************************************************************/ /*
		 * When outputting to an array, fill the ".tupno" element with the
		 * current tuple number.  This will be overridden below if ".tupno" is
		 * in use as an actual field name in the rowtype.
		 */ /* ignore dropped attributes */ /************************************************************
		 * Get the attribute name
		 ************************************************************/ /************************************************************
		 * Get the attributes value
		 ************************************************************/ /************************************************************
		 * If there is a value, set the variable
		 * If not, unset it
		 *
		 * Hmmm - Null attributes will cause functions to
		 *		  crash if they don't expect them - need something
		 *		  smarter here.
		 ************************************************************/