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

Function function_parse_error_transpose

src/backend/catalog/pg_proc.c:1085–1134  ·  view source on GitHub ↗

* Adjust a syntax error occurring inside the function body of a CREATE * FUNCTION or DO command. This can be used by any function validator or * anonymous-block handler, not only for SQL-language functions. * It is assumed that the syntax error position is initially relative to the * function body string (as passed in). If possible, we adjust the position * to reference the original command

Source from the content-addressed store, hash-verified

1083 * Returns true if a syntax error was processed, false if not.
1084 */
1085bool
1086function_parse_error_transpose(const char *prosrc)
1087{
1088 int origerrposition;
1089 int newerrposition;
1090 const char *queryText;
1091
1092 /*
1093 * Nothing to do unless we are dealing with a syntax error that has a
1094 * cursor position.
1095 *
1096 * Some PLs may prefer to report the error position as an internal error
1097 * to begin with, so check that too.
1098 */
1099 origerrposition = geterrposition();
1100 if (origerrposition <= 0)
1101 {
1102 origerrposition = getinternalerrposition();
1103 if (origerrposition <= 0)
1104 return false;
1105 }
1106
1107 /* We can get the original query text from the active portal (hack...) */
1108 /* Assert(ActivePortal && PortalGetStatus(ActivePortal) == PORTAL_ACTIVE); */
1109 queryText = ActivePortal->sourceText;
1110
1111 /* Try to locate the prosrc in the original text */
1112 newerrposition = match_prosrc_to_query(prosrc, queryText, origerrposition);
1113
1114 if (newerrposition > 0)
1115 {
1116 /* Successful, so fix error position to reference original query */
1117 errposition(newerrposition);
1118 /* Get rid of any report of the error as an "internal query" */
1119 internalerrposition(0);
1120 internalerrquery(NULL);
1121 }
1122 else
1123 {
1124 /*
1125 * If unsuccessful, convert the position to an internal position
1126 * marker and give the function text as the internal query.
1127 */
1128 errposition(0);
1129 internalerrposition(origerrposition);
1130 internalerrquery(prosrc);
1131 }
1132
1133 return true;
1134}
1135
1136/*
1137 * Try to locate the string literal containing the function body in the

Calls 6

match_prosrc_to_queryFunction · 0.85
geterrpositionFunction · 0.50
getinternalerrpositionFunction · 0.50
errpositionFunction · 0.50
internalerrpositionFunction · 0.50
internalerrqueryFunction · 0.50

Tested by

no test coverage detected