MCPcopy Create free account
hub / github.com/apache/cloudberry / plpgsql_ns_lookup

Function plpgsql_ns_lookup

src/pl/plpgsql/src/pl_funcs.c:129–187  ·  view source on GitHub ↗

---------- * plpgsql_ns_lookup Lookup an identifier in the given namespace chain * * Note that this only searches for variables, not labels. * * If localmode is true, only the topmost block level is searched. * * name1 must be non-NULL. Pass NULL for name2 and/or name3 if parsing a name * with fewer than three components. * * If names_used isn't NULL, *names_used receives the number of

Source from the content-addressed store, hash-verified

127 * ----------
128 */
129PLpgSQL_nsitem *
130plpgsql_ns_lookup(PLpgSQL_nsitem *ns_cur, bool localmode,
131 const char *name1, const char *name2, const char *name3,
132 int *names_used)
133{
134 /* Outer loop iterates once per block level in the namespace chain */
135 while (ns_cur != NULL)
136 {
137 PLpgSQL_nsitem *nsitem;
138
139 /* Check this level for unqualified match to variable name */
140 for (nsitem = ns_cur;
141 nsitem->itemtype != PLPGSQL_NSTYPE_LABEL;
142 nsitem = nsitem->prev)
143 {
144 if (strcmp(nsitem->name, name1) == 0)
145 {
146 if (name2 == NULL ||
147 nsitem->itemtype != PLPGSQL_NSTYPE_VAR)
148 {
149 if (names_used)
150 *names_used = 1;
151 return nsitem;
152 }
153 }
154 }
155
156 /* Check this level for qualified match to variable name */
157 if (name2 != NULL &&
158 strcmp(nsitem->name, name1) == 0)
159 {
160 for (nsitem = ns_cur;
161 nsitem->itemtype != PLPGSQL_NSTYPE_LABEL;
162 nsitem = nsitem->prev)
163 {
164 if (strcmp(nsitem->name, name2) == 0)
165 {
166 if (name3 == NULL ||
167 nsitem->itemtype != PLPGSQL_NSTYPE_VAR)
168 {
169 if (names_used)
170 *names_used = 2;
171 return nsitem;
172 }
173 }
174 }
175 }
176
177 if (localmode)
178 break; /* do not look into upper levels */
179
180 ns_cur = nsitem->prev;
181 }
182
183 /* This is just to suppress possibly-uninitialized-variable warnings */
184 if (names_used)
185 *names_used = 0;
186 return NULL; /* No match found */

Callers 8

add_parameter_nameFunction · 0.85
plpgsql_param_refFunction · 0.85
resolve_column_refFunction · 0.85
plpgsql_parse_wordFunction · 0.85
plpgsql_parse_dblwordFunction · 0.85
plpgsql_parse_tripwordFunction · 0.85
plpgsql_parse_wordtypeFunction · 0.85
plpgsql_parse_cwordtypeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected