1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
From 5dbcd9779ae6b5d5008aaddfa62677adf05dd5e5 Mon Sep 17 00:00:00 2001
From: Pavel Stehule <pavel.stehule@gmail.com>
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 <pavel.stehule@gmail.com>
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;
|