Skip to content

Commit 4de37ba

Browse files
committed
fix compilation and tests for 9.4
1 parent c1c36cd commit 4de37ba

File tree

7 files changed

+211
-67
lines changed

7 files changed

+211
-67
lines changed

expected/README

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ plpgsql_check_active_4.out PostgreSQL 9.6
44
plpgsql_check_active.out PostgreSQL 11, 12
55
plpgsql_check_active_1.out PostgreSQL 10
66

7+
plpgsql_check_passive_2.out PostgreSQL 9.4
8+

expected/plpgsql_check_active-9.4.out

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,11 @@ select * from plpgsql_check_function('fx2()', performance_warnings := true);
296296
-----------------------------------------------------------------------------------------
297297
performance:42804:5:assignment:target type has type modificator
298298
Hint: Usage of type modificator enforces slower IO casting.
299+
Context: at assignment to variable "pa.pa_id" declared on line 0
299300
warning extra:00000:2:DECLARE:never read variable "_pa"
300301
performance:00000:routine is marked as VOLATILE, should be STABLE
301302
Hint: When you fix this issue, please, recheck other functions that uses this function.
302-
(5 rows)
303+
(6 rows)
303304

304305
drop function fx2();
305306
create or replace function test_lab()

expected/plpgsql_check_active_2.out

Lines changed: 159 additions & 54 deletions
Large diffs are not rendered by default.

expected/plpgsql_check_passive.out

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,14 @@ begin
252252
end;
253253
$$ language plpgsql;
254254
select f1();
255-
ERROR: too many parameters specified for RAISE
256-
CONTEXT: compilation of PL/pgSQL function "f1" near line 4
255+
WARNING: too many parameters specified for RAISE
256+
CONTEXT: PL/pgSQL function f1() line 4 at RAISE
257+
PL/pgSQL function f1() line 4 at RAISE
258+
f1
259+
----
260+
261+
(1 row)
262+
257263
drop function f1();
258264
create or replace function f1()
259265
returns void as $$
@@ -264,6 +270,12 @@ begin
264270
end;
265271
$$ language plpgsql;
266272
select f1();
267-
ERROR: too few parameters specified for RAISE
268-
CONTEXT: compilation of PL/pgSQL function "f1" near line 4
273+
WARNING: too few parameters specified for RAISE
274+
CONTEXT: PL/pgSQL function f1() line 4 at RAISE
275+
PL/pgSQL function f1() line 4 at RAISE
276+
f1
277+
----
278+
279+
(1 row)
280+
269281
drop function f1();

expected/plpgsql_check_passive_2.out

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ end;
8585
$$ language plpgsql;
8686
select f1();
8787
ERROR: record "r" has no field "c"
88-
CONTEXT: PL/pgSQL function f1() line 6 at assignment
88+
CONTEXT: PL/pgSQL function f1() line 6 at assignment to field "c" of variable "r" declared on line 2
8989
drop function f1();
9090
drop function g1();
9191
create function f1()
@@ -103,7 +103,7 @@ ERROR: column "a" does not exist
103103
LINE 1: SELECT a + b
104104
^
105105
QUERY: SELECT a + b
106-
CONTEXT: PL/pgSQL function f1() line 5 at assignment
106+
CONTEXT: PL/pgSQL function f1() line 5 at assignment to variable "r" declared on line 2
107107
drop function f1();
108108
create or replace function f1()
109109
returns void as $$
@@ -119,7 +119,7 @@ ERROR: column "c" does not exist
119119
LINE 1: SELECT c+10
120120
^
121121
QUERY: SELECT c+10
122-
CONTEXT: PL/pgSQL function f1() line 5 at assignment
122+
CONTEXT: PL/pgSQL function f1() line 5 at assignment to element of variable "r" declared on line 2
123123
drop function f1();
124124
create or replace function f1()
125125
returns void as $$
@@ -132,7 +132,7 @@ end;
132132
$$ language plpgsql;
133133
select f1();
134134
ERROR: subscripted object is not an array
135-
CONTEXT: PL/pgSQL function f1() line 5 at assignment
135+
CONTEXT: PL/pgSQL function f1() line 5 at assignment to element of variable "r" declared on line 2
136136
drop function f1();
137137
create or replace function f1()
138138
returns void as $$

sql/plpgsql_check_active.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2441,8 +2441,8 @@ begin
24412441
end;
24422442
$$ language plpgsql volatile;
24432443

2444-
select * from plpgsql_check_function('flag_test1(int)', performance_warnings => true);
2445-
select * from plpgsql_check_function('flag_test2(int)', performance_warnings => true);
2444+
select * from plpgsql_check_function('flag_test1(int)', performance_warnings := true);
2445+
select * from plpgsql_check_function('flag_test2(int)', performance_warnings := true);
24462446

24472447
drop table fufu;
24482448
drop function flag_test1(int);
@@ -2576,7 +2576,7 @@ end;
25762576
$$ language plpgsql;
25772577

25782578
-- should not to crash
2579-
select * from plpgsql_check_function('test_crash', fatal_errors=>false);
2580-
select * from plpgsql_check_function('test_crash', fatal_errors=>true);
2579+
select * from plpgsql_check_function('test_crash', fatal_errors := false);
2580+
select * from plpgsql_check_function('test_crash', fatal_errors := true);
25812581

25822582
drop function test_crash();

src/stmtwalk.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,17 @@
1313

1414
#include "access/tupconvert.h"
1515
#include "catalog/pg_type.h"
16+
17+
#if PG_VERSION_NUM > 90500
18+
1619
#include "common/keywords.h"
1720

21+
#else
22+
23+
#include "parser/keywords.h"
24+
25+
#endif
26+
1827
static void check_stmts(PLpgSQL_checkstate *cstate, List *stmts, int *closing, List **exceptions);
1928
static PLpgSQL_stmt_stack_item * push_stmt_to_stmt_stack(PLpgSQL_checkstate *cstate);
2029
static void pop_stmt_from_stmt_stack(PLpgSQL_checkstate *cstate);
@@ -164,13 +173,28 @@ plpgsql_check_stmt(PLpgSQL_checkstate *cstate, PLpgSQL_stmt *stmt, int *closing,
164173

165174
cstate->estate->err_text = str.data;
166175

176+
#if PG_VERSION_NUM >= 110000
177+
167178
if (var->default_val)
168179
plpgsql_check_assignment(cstate,
169180
var->default_val,
170181
NULL,
171182
NULL,
172183
var->dno);
173184

185+
#else
186+
187+
if (d->dtype == PLPGSQL_DTYPE_VAR &&
188+
((PLpgSQL_var *) var)->default_val)
189+
plpgsql_check_assignment(cstate,
190+
((PLpgSQL_var *) var)->default_val,
191+
NULL,
192+
NULL,
193+
var->dno);
194+
195+
196+
#endif
197+
174198
cstate->estate->err_text = NULL;
175199
pfree(str.data);
176200
}

0 commit comments

Comments
 (0)