From 5dbcd9779ae6b5d5008aaddfa62677adf05dd5e5 Mon Sep 17 00:00:00 2001 From: Pavel Stehule Date: Wed, 10 Oct 2018 16:27:07 +0200 Subject: [PATCH] fix for PostgreSQL 11,12 Patch-Source: https://github.com/okbob/plpgsql_check/commit/5dbcd9779ae6b5d5008aaddfa62677adf05dd5e5 --- plpgsql_check.c | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/plpgsql_check.c b/plpgsql_check.c index 8a83b06..b95adf1 100644 --- a/plpgsql_check.c +++ b/plpgsql_check.c @@ -308,6 +308,8 @@ static int possibly_closed(int c); static Query *ExprGetQuery(PLpgSQL_checkstate *cstate, PLpgSQL_expr *query); static char *ExprGetString(PLpgSQL_checkstate *cstate, PLpgSQL_expr *query, bool *IsConst); static bool exception_matches_conditions(int err_code, PLpgSQL_condition *cond); +static bool is_internal_variable(PLpgSQL_variable *var); + #if PG_VERSION_NUM >= 110000 @@ -3398,9 +3400,17 @@ is_internal(char *refname, int lineno) return true; if (strcmp(refname, "*internal*") == 0) return true; + if (strcmp(refname, "(unnamed row)") == 0) + return true; return false; } +static bool +is_internal_variable(PLpgSQL_variable *var) +{ + return is_internal(var->refname, var->lineno); +} + /* * Returns true if dno is explicitly declared. It should not be used @@ -3635,7 +3645,7 @@ report_unused_variables(PLpgSQL_checkstate *cstate) int varno = func->out_param_varno; PLpgSQL_variable *var = (PLpgSQL_variable *) estate->datums[varno]; - if (var->dtype == PLPGSQL_DTYPE_ROW && var->refname == NULL) + if (var->dtype == PLPGSQL_DTYPE_ROW && is_internal_variable(var)) { /* this function has more OUT parameters */ PLpgSQL_row *row = (PLpgSQL_row*) var; @@ -5682,25 +5692,46 @@ check_fishy_qual(PLpgSQL_checkstate *cstate, PLpgSQL_expr *query) } /* - * returns refname of PLpgSQL_datum + * returns refname of PLpgSQL_datum. When refname is generated, + * then return null too, although refname is not null. */ static char * datum_get_refname(PLpgSQL_datum *d) { + char *refname; + int lineno; + switch (d->dtype) { case PLPGSQL_DTYPE_VAR: - return ((PLpgSQL_var *) d)->refname; + refname = ((PLpgSQL_var *) d)->refname; + lineno = ((PLpgSQL_var *) d)->lineno; + break; case PLPGSQL_DTYPE_ROW: - return ((PLpgSQL_row *) d)->refname; + refname = ((PLpgSQL_row *) d)->refname; + lineno = ((PLpgSQL_row *) d)->lineno; + break; case PLPGSQL_DTYPE_REC: - return ((PLpgSQL_rec *) d)->refname; + refname = ((PLpgSQL_rec *) d)->refname; + lineno = ((PLpgSQL_rec *) d)->lineno; + break; default: - return NULL; + refname = NULL; + lineno = -1; } + + /* + * PostgreSQL 12 started use "(unnamed row)" name for internal + * variables. Hide this name too (lineno is -1). + */ + if (strcmp(refname, "(unnamed row)") == 0 + && lineno == -1) + return NULL; + + return refname; } /**************************************************************************************** From b9564b563f99630fcc1fe19d74fb466d899090b8 Mon Sep 17 00:00:00 2001 From: Pavel Stehule Date: Wed, 10 Oct 2018 16:32:56 +0200 Subject: [PATCH] minor change Patch-Source: https://github.com/okbob/plpgsql_check/commit/b9564b563f99630fcc1fe19d74fb466d899090b8 --- plpgsql_check.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plpgsql_check.c b/plpgsql_check.c index b95adf1..f9f4e1b 100644 --- a/plpgsql_check.c +++ b/plpgsql_check.c @@ -5727,8 +5727,7 @@ datum_get_refname(PLpgSQL_datum *d) * PostgreSQL 12 started use "(unnamed row)" name for internal * variables. Hide this name too (lineno is -1). */ - if (strcmp(refname, "(unnamed row)") == 0 - && lineno == -1) + if (is_internal(refname, lineno)) return NULL; return refname;