diff options
Diffstat (limited to 'src/bin/psql/command.c')
-rw-r--r-- | src/bin/psql/command.c | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index fb1e69ec4c2..bb94df50a63 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -167,8 +167,7 @@ static bool get_create_object_cmd(EditableObjectType obj_type, Oid oid, PQExpBuffer buf); static int strip_lineno_from_objdesc(char *obj); static int count_lines_in_buf(PQExpBuffer buf); -static void print_with_linenumbers(FILE *output, char *lines, - const char *header_keyword); +static void print_with_linenumbers(FILE *output, char *lines, bool is_func); static void minimal_error_message(PGresult *res); static void printSSLInfo(void); @@ -1170,17 +1169,19 @@ exec_command_ef_ev(PsqlScanState scan_state, bool active_branch, /* * lineno "1" should correspond to the first line of the * function body. We expect that pg_get_functiondef() will - * emit that on a line beginning with "AS ", and that there - * can be no such line before the real start of the function - * body. Increment lineno by the number of lines before that - * line, so that it becomes relative to the first line of the - * function definition. + * emit that on a line beginning with "AS ", "BEGIN ", or + * "RETURN ", and that there can be no such line before the + * real start of the function body. Increment lineno by the + * number of lines before that line, so that it becomes + * relative to the first line of the function definition. */ const char *lines = query_buf->data; while (*lines != '\0') { - if (strncmp(lines, "AS ", 3) == 0) + if (strncmp(lines, "AS ", 3) == 0 || + strncmp(lines, "BEGIN ", 6) == 0 || + strncmp(lines, "RETURN ", 7) == 0) break; lineno++; /* find start of next line */ @@ -2502,15 +2503,8 @@ exec_command_sf_sv(PsqlScanState scan_state, bool active_branch, if (show_linenumbers) { - /* - * For functions, lineno "1" should correspond to the first - * line of the function body. We expect that - * pg_get_functiondef() will emit that on a line beginning - * with "AS ", and that there can be no such line before the - * real start of the function body. - */ - print_with_linenumbers(output, buf->data, - is_func ? "AS " : NULL); + /* add line numbers */ + print_with_linenumbers(output, buf->data, is_func); } else { @@ -5530,24 +5524,28 @@ count_lines_in_buf(PQExpBuffer buf) /* * Write text at *lines to output with line numbers. * - * If header_keyword isn't NULL, then line 1 should be the first line beginning - * with header_keyword; lines before that are unnumbered. + * For functions, lineno "1" should correspond to the first line of the + * function body; lines before that are unnumbered. We expect that + * pg_get_functiondef() will emit that on a line beginning with "AS ", + * "BEGIN ", or "RETURN ", and that there can be no such line before + * the real start of the function body. * * Caution: this scribbles on *lines. */ static void -print_with_linenumbers(FILE *output, char *lines, - const char *header_keyword) +print_with_linenumbers(FILE *output, char *lines, bool is_func) { - bool in_header = (header_keyword != NULL); - size_t header_sz = in_header ? strlen(header_keyword) : 0; + bool in_header = is_func; int lineno = 0; while (*lines != '\0') { char *eol; - if (in_header && strncmp(lines, header_keyword, header_sz) == 0) + if (in_header && + (strncmp(lines, "AS ", 3) == 0 || + strncmp(lines, "BEGIN ", 6) == 0 || + strncmp(lines, "RETURN ", 7) == 0)) in_header = false; /* increment lineno only for body's lines */ |