src/pl/tcl/pltcl.c
static Tcl_Obj *
pltcl_build_tuple_argument(HeapTuple tuple, TupleDesc tupdesc, bool include_generated)
{
	Tcl_Obj    *retobj = Tcl_NewObj();
	int			i;
	char	   *outputstr;
	Datum		attr;
	bool		isnull;
	char	   *attname;
	Oid			typoutput;
	bool		typisvarlena;

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

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

		if (att->attgenerated)
		{
			/* don't include unless requested */
			if (!include_generated)
				continue;
		}

		/************************************************************
		 * Get the attribute name
		 ************************************************************/
		attname = NameStr(att->attname);

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

		/************************************************************
		 * If there is a value, append the attribute name and the
		 * value to the list
		 *
		 * 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_ListObjAppendElement(NULL, retobj,
									 Tcl_NewStringObj(UTF_E2U(attname), -1));
			UTF_END;
			UTF_BEGIN;
			Tcl_ListObjAppendElement(NULL, retobj,
									 Tcl_NewStringObj(UTF_E2U(outputstr), -1));
			UTF_END;
			pfree(outputstr);
		}
	}

	return retobj;
}
/**********************************************************************
 * pltcl_build_tuple_argument() - Build a list object usable for 'array set'
 *				  from all attributes of a given tuple
 **********************************************************************/
Build a list object usable for 'array set'
from all attributes of a given tuple
Build a list object usable for ' array set ' from all attributes of a given tuple
static Tcl_Obj *
pltcl_build_tuple_argument(HeapTuple tuple, TupleDesc tupdesc, bool include_generated)
{
	Tcl_Obj    *retobj = Tcl_NewObj();
	int			i;
	char	   *outputstr;
	Datum		attr;
	bool		isnull;
	char	   *attname;
	Oid			typoutput;
	bool		typisvarlena;
	for (i = 0; i < tupdesc->natts; i++)
	{
		Form_pg_attribute att = TupleDescAttr(tupdesc, i);
		if (att->attisdropped)
			continue;
		if (att->attgenerated)
		{
			if (!include_generated)
				continue;
		}
		attname = NameStr(att->attname);
		attr = heap_getattr(tuple, i + 1, tupdesc, &isnull);
		if (!isnull)
		{
			getTypeOutputInfo(att->atttypid,
							  &typoutput, &typisvarlena);
			outputstr = OidOutputFunctionCall(typoutput, attr);
			UTF_BEGIN;
			Tcl_ListObjAppendElement(NULL, retobj,
									 Tcl_NewStringObj(UTF_E2U(attname), -1));
			UTF_END;
			UTF_BEGIN;
			Tcl_ListObjAppendElement(NULL, retobj,
									 Tcl_NewStringObj(UTF_E2U(outputstr), -1));
			UTF_END;
			pfree(outputstr);
		}
	}
	return retobj;
}
static Tcl_Obj * pltcl_build_tuple_argument ( HeapTuple tuple , TupleDesc tupdesc , bool include_generated ) { Tcl_Obj * retobj = Tcl_NewObj ( ) ; int i ; char * outputstr ; Datum attr ; bool isnull ; char * attname ; Oid typoutput ; bool typisvarlena ; for ( i = 0 ; i < tupdesc -> natts ; i ++ ) { Form_pg_attribute att = TupleDescAttr ( tupdesc , i ) ; if ( att -> attisdropped ) continue ; if ( att -> attgenerated ) { if ( ! include_generated ) continue ; } attname = NameStr ( att -> attname ) ; attr = heap_getattr ( tuple , i + 1 , tupdesc , & isnull ) ; if ( ! isnull ) { getTypeOutputInfo ( att -> atttypid , & typoutput , & typisvarlena ) ; outputstr = OidOutputFunctionCall ( typoutput , attr ) ; UTF_BEGIN ; Tcl_ListObjAppendElement ( NULL , retobj , Tcl_NewStringObj ( UTF_E2U ( attname ) , -1 ) ) ; UTF_END ; UTF_BEGIN ; Tcl_ListObjAppendElement ( NULL , retobj , Tcl_NewStringObj ( UTF_E2U ( outputstr ) , -1 ) ) ; UTF_END ; pfree ( outputstr ) ; } } return retobj ; }
pltcl_build_tuple_argument() - Build a list object usable for 'array set'
                                from all attributes of a given tuple
pltcl_build_tuple_argument () - Build a list object usable for ' array set ' from all attributes of a given tuple
/* ignore dropped attributes */ /* don't include unless requested */ /************************************************************
		 * Get the attribute name
		 ************************************************************/ /************************************************************
		 * Get the attributes value
		 ************************************************************/ /************************************************************
		 * If there is a value, append the attribute name and the
		 * value to the list
		 *
		 * Hmmm - Null attributes will cause functions to
		 *		  crash if they don't expect them - need something
		 *		  smarter here.
		 ************************************************************/