25
25
#include "utils/lsyscache.h"
26
26
#include "utils/syscache.h"
27
27
28
+
29
+ static bool plpgsql_extra_checks_check_hook (char * * newvalue , void * * extra , GucSource source );
30
+ static void plpgsql_extra_warnings_assign_hook (const char * newvalue , void * extra );
31
+ static void plpgsql_extra_errors_assign_hook (const char * newvalue , void * extra );
32
+
28
33
PG_MODULE_MAGIC ;
29
34
30
35
/* Custom GUC variable */
@@ -39,10 +44,89 @@ int plpgsql_variable_conflict = PLPGSQL_RESOLVE_ERROR;
39
44
40
45
bool plpgsql_print_strict_params = false;
41
46
47
+ char * plpgsql_extra_warnings_string = NULL ;
48
+ char * plpgsql_extra_errors_string = NULL ;
49
+ int plpgsql_extra_warnings ;
50
+ int plpgsql_extra_errors ;
51
+
42
52
/* Hook for plugins */
43
53
PLpgSQL_plugin * * plugin_ptr = NULL ;
44
54
45
55
56
+ static bool
57
+ plpgsql_extra_checks_check_hook (char * * newvalue , void * * extra , GucSource source )
58
+ {
59
+ char * rawstring ;
60
+ List * elemlist ;
61
+ ListCell * l ;
62
+ int extrachecks = 0 ;
63
+ int * myextra ;
64
+
65
+ if (pg_strcasecmp (* newvalue , "all" ) == 0 )
66
+ extrachecks = PLPGSQL_XCHECK_ALL ;
67
+ else if (pg_strcasecmp (* newvalue , "none" ) == 0 )
68
+ extrachecks = PLPGSQL_XCHECK_NONE ;
69
+ else
70
+ {
71
+ /* Need a modifiable copy of string */
72
+ rawstring = pstrdup (* newvalue );
73
+
74
+ /* Parse string into list of identifiers */
75
+ if (!SplitIdentifierString (rawstring , ',' , & elemlist ))
76
+ {
77
+ /* syntax error in list */
78
+ GUC_check_errdetail ("List syntax is invalid." );
79
+ pfree (rawstring );
80
+ list_free (elemlist );
81
+ return false;
82
+ }
83
+
84
+ foreach (l , elemlist )
85
+ {
86
+ char * tok = (char * ) lfirst (l );
87
+
88
+ if (pg_strcasecmp (tok , "shadowed_variables" ) == 0 )
89
+ extrachecks |= PLPGSQL_XCHECK_SHADOWVAR ;
90
+ else if (pg_strcasecmp (tok , "all" ) == 0 || pg_strcasecmp (tok , "none" ) == 0 )
91
+ {
92
+ GUC_check_errdetail ("Key word \"%s\" cannot be combined with other key words." , tok );
93
+ pfree (rawstring );
94
+ list_free (elemlist );
95
+ return false;
96
+ }
97
+ else
98
+ {
99
+ GUC_check_errdetail ("Unrecognized key word: \"%s\"." , tok );
100
+ pfree (rawstring );
101
+ list_free (elemlist );
102
+ return false;
103
+ }
104
+ }
105
+
106
+ pfree (rawstring );
107
+ list_free (elemlist );
108
+ }
109
+
110
+ myextra = (int * ) malloc (sizeof (int ));
111
+ * myextra = extrachecks ;
112
+ * extra = (void * ) myextra ;
113
+
114
+ return true;
115
+ }
116
+
117
+ static void
118
+ plpgsql_extra_warnings_assign_hook (const char * newvalue , void * extra )
119
+ {
120
+ plpgsql_extra_warnings = * ((int * ) extra );
121
+ }
122
+
123
+ static void
124
+ plpgsql_extra_errors_assign_hook (const char * newvalue , void * extra )
125
+ {
126
+ plpgsql_extra_errors = * ((int * ) extra );
127
+ }
128
+
129
+
46
130
/*
47
131
* _PG_init() - library load-time initialization
48
132
*
@@ -76,6 +160,26 @@ _PG_init(void)
76
160
PGC_USERSET , 0 ,
77
161
NULL , NULL , NULL );
78
162
163
+ DefineCustomStringVariable ("plpgsql.extra_warnings" ,
164
+ gettext_noop ("List of programming constructs which should produce a warning." ),
165
+ NULL ,
166
+ & plpgsql_extra_warnings_string ,
167
+ "none" ,
168
+ PGC_USERSET , GUC_LIST_INPUT ,
169
+ plpgsql_extra_checks_check_hook ,
170
+ plpgsql_extra_warnings_assign_hook ,
171
+ NULL );
172
+
173
+ DefineCustomStringVariable ("plpgsql.extra_errors" ,
174
+ gettext_noop ("List of programming constructs which should produce an error." ),
175
+ NULL ,
176
+ & plpgsql_extra_errors_string ,
177
+ "none" ,
178
+ PGC_USERSET , GUC_LIST_INPUT ,
179
+ plpgsql_extra_checks_check_hook ,
180
+ plpgsql_extra_errors_assign_hook ,
181
+ NULL );
182
+
79
183
EmitWarningsOnPlaceholders ("plpgsql" );
80
184
81
185
plpgsql_HashTableInit ();
0 commit comments