55 * command, configuration file, and command line options.
66 * See src/backend/utils/misc/README for more information.
77 *
8- * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.107 2002/11/21 00:42:19 tgl Exp $
8+ * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.108 2002/12/02 05:20:47 tgl Exp $
99 *
1010 * Copyright 2000 by PostgreSQL Global Development Group
1111 * Written by Peter Eisentraut <peter_e@gmx.net>.
@@ -2754,7 +2754,7 @@ assign_defaultxactisolevel(const char *newval, bool doit, bool interactive)
27542754
27552755/*
27562756 * Handle options fetched from pg_database.datconfig or pg_shadow.useconfig.
2757- * The array parameter must be an array of TEXT.
2757+ * The array parameter must be an array of TEXT (it must not be NULL) .
27582758 */
27592759void
27602760ProcessGUCArray (ArrayType * array ,GucSource source )
@@ -2809,7 +2809,10 @@ ProcessGUCArray(ArrayType *array, GucSource source)
28092809}
28102810
28112811
2812-
2812+ /*
2813+ * Add an entry to an option array. The array parameter may be NULL
2814+ * to indicate the current table entry is NULL.
2815+ */
28132816ArrayType *
28142817GUCArrayAdd (ArrayType * array ,const char * name ,const char * value )
28152818{
@@ -2880,7 +2883,11 @@ GUCArrayAdd(ArrayType *array, const char *name, const char *value)
28802883}
28812884
28822885
2883-
2886+ /*
2887+ * Delete an entry from an option array. The array parameter may be NULL
2888+ * to indicate the current table entry is NULL. Also, if the return value
2889+ * is NULL then a null should be stored.
2890+ */
28842891ArrayType *
28852892GUCArrayDelete (ArrayType * array ,const char * name )
28862893{
@@ -2889,16 +2896,17 @@ GUCArrayDelete(ArrayType *array, const char *name)
28892896int index ;
28902897
28912898Assert (name );
2892- Assert (array );
28932899
28942900/* test if the option is valid */
28952901set_config_option (name ,NULL ,
28962902superuser () ?PGC_SUSET :PGC_USERSET ,
28972903PGC_S_SESSION , false, false);
28982904
2899- newarray = construct_array (NULL ,0 ,
2900- TEXTOID ,
2901- -1 , false,'i' );
2905+ /* if array is currently null, then surely nothing to delete */
2906+ if (!array )
2907+ return NULL ;
2908+
2909+ newarray = NULL ;
29022910index = 1 ;
29032911
29042912for (i = 1 ;i <=ARR_DIMS (array )[0 ];i ++ )
@@ -2917,18 +2925,28 @@ GUCArrayDelete(ArrayType *array, const char *name)
29172925continue ;
29182926val = DatumGetCString (DirectFunctionCall1 (textout ,d ));
29192927
2928+ /* ignore entry if it's what we want to delete */
29202929if (strncmp (val ,name ,strlen (name ))== 0
29212930&& val [strlen (name )]== '=' )
29222931continue ;
29232932
2924- isnull = false;
2925- newarray = array_set (newarray ,1 ,& index ,
2926- d ,
2927- -1 /* varlenarray */ ,
2928- -1 /* TEXT's typlen */ ,
2929- false/* TEXT's typbyval */ ,
2930- 'i' /* TEXT's typalign */ ,
2931- & isnull );
2933+ /* else add it to the output array */
2934+ if (newarray )
2935+ {
2936+ isnull = false;
2937+ newarray = array_set (newarray ,1 ,& index ,
2938+ d ,
2939+ -1 /* varlenarray */ ,
2940+ -1 /* TEXT's typlen */ ,
2941+ false/* TEXT's typbyval */ ,
2942+ 'i' /* TEXT's typalign */ ,
2943+ & isnull );
2944+ }
2945+ else
2946+ newarray = construct_array (& d ,1 ,
2947+ TEXTOID ,
2948+ -1 , false,'i' );
2949+
29322950index ++ ;
29332951}
29342952