src/backend/utils/misc/guc.c
ArrayType *
GUCArrayAdd(ArrayType *array, const char *name, const char *value)
{
	const char *varname;
	Datum		datum;
	char	   *newval;
	ArrayType  *a;

	Assert(name);
	Assert(value);

	/* test if the option is valid */
	set_config_option(name, value,
					  superuser() ? PGC_SUSET : PGC_USERSET,
					  PGC_S_TEST, false, false);

	/* convert name to canonical spelling, so we can use plain strcmp */
	(void) GetConfigOptionByName(name, &varname);
	name = varname;

	newval = palloc(strlen(name) + 1 + strlen(value) + 1);
	sprintf(newval, "%s=%s", name, value);
	datum = DirectFunctionCall1(textin, CStringGetDatum(newval));

	if (array)
	{
		int			index;
		bool		isnull;
		int			i;

		Assert(ARR_ELEMTYPE(array) == TEXTOID);
		Assert(ARR_NDIM(array) == 1);
		Assert(ARR_LBOUND(array)[0] == 1);

		index = ARR_DIMS(array)[0] + 1; /* add after end */

		for (i = 1; i <= ARR_DIMS(array)[0]; i++)
		{
			Datum		d;
			char	   *current;

			d = array_ref(array, 1, &i,
						  -1 /* varlenarray */ ,
						  -1 /* TEXT's typlen */ ,
						  false /* TEXT's typbyval */ ,
						  'i' /* TEXT's typalign */ ,
						  &isnull);
			if (isnull)
				continue;
			current = DatumGetCString(DirectFunctionCall1(textout, d));
			if (strncmp(current, newval, strlen(name) + 1) == 0)
			{
				index = i;
				break;
			}
		}

		a = array_set(array, 1, &index,
					  datum,
					  false,
					  -1 /* varlena array */ ,
					  -1 /* TEXT's typlen */ ,
					  false /* TEXT's typbyval */ ,
					  'i' /* TEXT's typalign */ );
	}
	else
		a = construct_array(&datum, 1,
							TEXTOID,
							-1, false, 'i');

	return a;
}
/*
 * Add an entry to an option array.  The array parameter may be NULL
 * to indicate the current table entry is NULL.
 */
Add an entry to an option array.  The array parameter may be NULL
to indicate the current table entry is NULL.
Add an entry to an option array . The array parameter may be NULL to indicate the current table entry is NULL .
ArrayType *
GUCArrayAdd(ArrayType *array, const char *name, const char *value)
{
	const char *varname;
	Datum		datum;
	char	   *newval;
	ArrayType  *a;
	Assert(name);
	Assert(value);
	set_config_option(name, value,
					  superuser() ? PGC_SUSET : PGC_USERSET,
					  PGC_S_TEST, false, false);
	(void) GetConfigOptionByName(name, &varname);
	name = varname;
	newval = palloc(strlen(name) + 1 + strlen(value) + 1);
	sprintf(newval, "%s=%s", name, value);
	datum = DirectFunctionCall1(textin, CStringGetDatum(newval));
	if (array)
	{
		int			index;
		bool		isnull;
		int			i;
		Assert(ARR_ELEMTYPE(array) == TEXTOID);
		Assert(ARR_NDIM(array) == 1);
		Assert(ARR_LBOUND(array)[0] == 1);
		index = ARR_DIMS(array)[0] + 1; 
		for (i = 1; i <= ARR_DIMS(array)[0]; i++)
		{
			Datum		d;
			char	   *current;
			d = array_ref(array, 1, &i,
						  -1  ,
						  -1  ,
						  false  ,
						  'i'  ,
						  &isnull);
			if (isnull)
				continue;
			current = DatumGetCString(DirectFunctionCall1(textout, d));
			if (strncmp(current, newval, strlen(name) + 1) == 0)
			{
				index = i;
				break;
			}
		}
		a = array_set(array, 1, &index,
					  datum,
					  false,
					  -1  ,
					  -1  ,
					  false  ,
					  'i'  );
	}
	else
		a = construct_array(&datum, 1,
							TEXTOID,
							-1, false, 'i');
	return a;
}
ArrayType * GUCArrayAdd ( ArrayType * array , const char * name , const char * value ) { const char * varname ; Datum datum ; char * newval ; ArrayType * a ; Assert ( name ) ; Assert ( value ) ; set_config_option ( name , value , superuser ( ) ? PGC_SUSET : PGC_USERSET , PGC_S_TEST , false , false ) ; ( void ) GetConfigOptionByName ( name , & varname ) ; name = varname ; newval = palloc ( strlen ( name ) + 1 + strlen ( value ) + 1 ) ; sprintf ( newval , " " , name , value ) ; datum = DirectFunctionCall1 ( textin , CStringGetDatum ( newval ) ) ; if ( array ) { int index ; bool isnull ; int i ; Assert ( ARR_ELEMTYPE ( array ) == TEXTOID ) ; Assert ( ARR_NDIM ( array ) == 1 ) ; Assert ( ARR_LBOUND ( array ) [ 0 ] == 1 ) ; index = ARR_DIMS ( array ) [ 0 ] + 1 ; for ( i = 1 ; i <= ARR_DIMS ( array ) [ 0 ] ; i ++ ) { Datum d ; char * current ; d = array_ref ( array , 1 , & i , -1 , -1 , false , ' ' , & isnull ) ; if ( isnull ) continue ; current = DatumGetCString ( DirectFunctionCall1 ( textout , d ) ) ; if ( strncmp ( current , newval , strlen ( name ) + 1 ) == 0 ) { index = i ; break ; } } a = array_set ( array , 1 , & index , datum , false , -1 , -1 , false , ' ' ) ; } else a = construct_array ( & datum , 1 , TEXTOID , -1 , false , ' ' ) ; return a ; }
Add an entry to an option array.
Add an entry to an option array .
/* test if the option is valid */ /* convert name to canonical spelling, so we can use plain strcmp */ /* add after end */ /* varlenarray */ /* TEXT's typlen */ /* TEXT's typbyval */ /* TEXT's typalign */ /* varlena array */ /* TEXT's typlen */ /* TEXT's typbyval */ /* TEXT's typalign */