forked from nextgres/uplpgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupl_plpgsql.h
More file actions
1487 lines (1342 loc) · 44.2 KB
/
Copy pathupl_plpgsql.h
File metadata and controls
1487 lines (1342 loc) · 44.2 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*-------------------------------------------------------------------------
*
* plpgsql.h - Definitions for the PL/pgSQL
* procedural language
*
* Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 2003-2014, Jonah H. Harris <[email protected]>
* Portions Copyright (c) 2014-2026, NEXTGRES, LLC. <[email protected]>
*
* Derived from PostgreSQL src/pl/plpgsql/src/plpgsql.h; modifications are
* licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain a
* copy of the License in LICENSE or at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0 AND PostgreSQL
*
*
* IDENTIFICATION
* src/pl/plpgsql/src/plpgsql.h
*
*-------------------------------------------------------------------------
*/
#ifndef UPL_PLPGSQL_H
#define UPL_PLPGSQL_H
#include "access/xact.h"
#include "commands/event_trigger.h"
#include "commands/trigger.h"
#include "executor/spi.h"
#include "utils/expandedrecord.h"
#include "utils/funccache.h"
#include "utils/typcache.h"
/*
* Compatibility shims for building against PostgreSQL majors older than the
* development tree this code was forked from. Each name below arrived in
* PostgreSQL 19; on 18 and earlier an equivalent is provided here. This
* header is included, directly or transitively, by every forked exec/comp
* source that uses them.
*
* Inert on 19 and later — the whole block compiles away.
*/
#if PG_VERSION_NUM < 190000
/* No compact-attribute finalize step exists before the CompactAttribute work. */
#define TupleDescFinalize(td) ((void) 0)
/* Optimizer hint; a no-op is always correct. */
#ifndef pg_assume
#define pg_assume(expr) ((void) 0)
#endif
/* Intentional switch fall-through marker. */
#ifndef pg_fallthrough
#define pg_fallthrough /* fall through */
#endif
/* Bare "varlena" alias; struct varlena itself has always existed. */
typedef struct varlena varlena;
#endif
/**********************************************************************
* Definitions
**********************************************************************/
/* define our text domain for translations */
#undef TEXTDOMAIN
#define TEXTDOMAIN PG_TEXTDOMAIN("plpgsql")
#undef _
#define _(x) dgettext(TEXTDOMAIN, x)
/*
* Compiler's namespace item types
*/
typedef enum UPLpgSQL_nsitem_type
{
UPLPGSQL_NSTYPE_LABEL, /* block label */
UPLPGSQL_NSTYPE_VAR, /* scalar variable */
UPLPGSQL_NSTYPE_REC, /* composite variable */
} UPLpgSQL_nsitem_type;
/*
* A UPLPGSQL_NSTYPE_LABEL stack entry must be one of these types
*/
typedef enum UPLpgSQL_label_type
{
UPLPGSQL_LABEL_BLOCK, /* DECLARE/BEGIN block */
UPLPGSQL_LABEL_LOOP, /* looping construct */
UPLPGSQL_LABEL_OTHER, /* anything else */
} UPLpgSQL_label_type;
/*
* Datum array node types
*/
typedef enum UPLpgSQL_datum_type
{
UPLPGSQL_DTYPE_VAR,
UPLPGSQL_DTYPE_ROW,
UPLPGSQL_DTYPE_REC,
UPLPGSQL_DTYPE_RECFIELD,
UPLPGSQL_DTYPE_PROMISE,
} UPLpgSQL_datum_type;
/*
* DTYPE_PROMISE datums have these possible ways of computing the promise
*/
typedef enum UPLpgSQL_promise_type
{
UPLPGSQL_PROMISE_NONE = 0, /* not a promise, or promise satisfied */
UPLPGSQL_PROMISE_TG_NAME,
UPLPGSQL_PROMISE_TG_WHEN,
UPLPGSQL_PROMISE_TG_LEVEL,
UPLPGSQL_PROMISE_TG_OP,
UPLPGSQL_PROMISE_TG_RELID,
UPLPGSQL_PROMISE_TG_TABLE_NAME,
UPLPGSQL_PROMISE_TG_TABLE_SCHEMA,
UPLPGSQL_PROMISE_TG_NARGS,
UPLPGSQL_PROMISE_TG_ARGV,
UPLPGSQL_PROMISE_TG_EVENT,
UPLPGSQL_PROMISE_TG_TAG,
} UPLpgSQL_promise_type;
/*
* Variants distinguished in UPLpgSQL_type structs
*/
typedef enum UPLpgSQL_type_type
{
UPLPGSQL_TTYPE_SCALAR, /* scalar types and domains */
UPLPGSQL_TTYPE_REC, /* composite types, including RECORD */
UPLPGSQL_TTYPE_PSEUDO, /* pseudotypes */
} UPLpgSQL_type_type;
/*
* Execution tree node types
*/
typedef enum UPLpgSQL_stmt_type
{
UPLPGSQL_STMT_BLOCK,
UPLPGSQL_STMT_ASSIGN,
UPLPGSQL_STMT_IF,
UPLPGSQL_STMT_CASE,
UPLPGSQL_STMT_LOOP,
UPLPGSQL_STMT_WHILE,
UPLPGSQL_STMT_FORI,
UPLPGSQL_STMT_FORS,
UPLPGSQL_STMT_FORC,
UPLPGSQL_STMT_FOREACH_A,
UPLPGSQL_STMT_EXIT,
UPLPGSQL_STMT_RETURN,
UPLPGSQL_STMT_RETURN_NEXT,
UPLPGSQL_STMT_RETURN_QUERY,
UPLPGSQL_STMT_RAISE,
UPLPGSQL_STMT_ASSERT,
UPLPGSQL_STMT_EXECSQL,
UPLPGSQL_STMT_DYNEXECUTE,
UPLPGSQL_STMT_DYNFORS,
UPLPGSQL_STMT_GETDIAG,
UPLPGSQL_STMT_OPEN,
UPLPGSQL_STMT_FETCH,
UPLPGSQL_STMT_CLOSE,
UPLPGSQL_STMT_PERFORM,
UPLPGSQL_STMT_CALL,
UPLPGSQL_STMT_COMMIT,
UPLPGSQL_STMT_ROLLBACK,
} UPLpgSQL_stmt_type;
/*
* Execution node return codes
*/
enum
{
UPLPGSQL_RC_OK,
UPLPGSQL_RC_EXIT,
UPLPGSQL_RC_RETURN,
UPLPGSQL_RC_CONTINUE,
};
/*
* GET DIAGNOSTICS information items
*/
typedef enum UPLpgSQL_getdiag_kind
{
UPLPGSQL_GETDIAG_ROW_COUNT,
UPLPGSQL_GETDIAG_ROUTINE_OID,
UPLPGSQL_GETDIAG_CONTEXT,
UPLPGSQL_GETDIAG_ERROR_CONTEXT,
UPLPGSQL_GETDIAG_ERROR_DETAIL,
UPLPGSQL_GETDIAG_ERROR_HINT,
UPLPGSQL_GETDIAG_RETURNED_SQLSTATE,
UPLPGSQL_GETDIAG_COLUMN_NAME,
UPLPGSQL_GETDIAG_CONSTRAINT_NAME,
UPLPGSQL_GETDIAG_DATATYPE_NAME,
UPLPGSQL_GETDIAG_MESSAGE_TEXT,
UPLPGSQL_GETDIAG_TABLE_NAME,
UPLPGSQL_GETDIAG_SCHEMA_NAME,
} UPLpgSQL_getdiag_kind;
/*
* RAISE statement options
*/
typedef enum UPLpgSQL_raise_option_type
{
UPLPGSQL_RAISEOPTION_ERRCODE,
UPLPGSQL_RAISEOPTION_MESSAGE,
UPLPGSQL_RAISEOPTION_DETAIL,
UPLPGSQL_RAISEOPTION_HINT,
UPLPGSQL_RAISEOPTION_COLUMN,
UPLPGSQL_RAISEOPTION_CONSTRAINT,
UPLPGSQL_RAISEOPTION_DATATYPE,
UPLPGSQL_RAISEOPTION_TABLE,
UPLPGSQL_RAISEOPTION_SCHEMA,
} UPLpgSQL_raise_option_type;
/*
* Behavioral modes for plpgsql variable resolution
*/
typedef enum UPLpgSQL_resolve_option
{
UPLPGSQL_RESOLVE_ERROR, /* throw error if ambiguous */
UPLPGSQL_RESOLVE_VARIABLE, /* prefer plpgsql var to table column */
UPLPGSQL_RESOLVE_COLUMN, /* prefer table column to plpgsql var */
} UPLpgSQL_resolve_option;
/*
* Status of optimization of assignment to a read/write expanded object
*/
typedef enum UPLpgSQL_rwopt
{
UPLPGSQL_RWOPT_UNKNOWN = 0, /* applicability not determined yet */
UPLPGSQL_RWOPT_NOPE, /* cannot do any optimization */
UPLPGSQL_RWOPT_TRANSFER, /* transfer the old value into expr state */
UPLPGSQL_RWOPT_INPLACE, /* pass value as R/W to top-level function */
} UPLpgSQL_rwopt;
/**********************************************************************
* Node and structure definitions
**********************************************************************/
/*
* Postgres data type
*/
typedef struct UPLpgSQL_type
{
char *typname; /* (simple) name of the type */
Oid typoid; /* OID of the data type */
UPLpgSQL_type_type ttype; /* UPLPGSQL_TTYPE_ code */
int16 typlen; /* stuff copied from its pg_type entry */
bool typbyval;
char typtype;
Oid collation; /* from pg_type, but can be overridden */
bool typisarray; /* is "true" array, or domain over one */
int32 atttypmod; /* typmod (taken from someplace else) */
/* Remaining fields are used only for named composite types (not RECORD) */
TypeName *origtypname; /* type name as written by user */
TypeCacheEntry *tcache; /* typcache entry for composite type */
uint64 tupdesc_id; /* last-seen tupdesc identifier */
} UPLpgSQL_type;
/*
* SQL Query to plan and execute
*/
typedef struct UPLpgSQL_expr
{
char *query; /* query string, verbatim from function body */
RawParseMode parseMode; /* raw_parser() mode to use */
struct UPLpgSQL_function *func; /* function containing this expr */
struct UPLpgSQL_nsitem *ns; /* namespace chain visible to this expr */
/*
* These fields are used to help optimize assignments to expanded-datum
* variables. If this expression is the source of an assignment to a
* simple variable, target_param holds that variable's dno (else it's -1),
* and target_is_local indicates whether the target is declared inside the
* closest exception block containing the assignment.
*/
int target_param; /* dno of assign target, or -1 if none */
bool target_is_local; /* is it within nearest exception block? */
/*
* Fields above are set during plpgsql parsing. Remaining fields are left
* as zeroes/NULLs until we first parse/plan the query.
*/
SPIPlanPtr plan; /* plan, or NULL if not made yet */
Bitmapset *paramnos; /* all dnos referenced by this query */
/* fields for "simple expression" fast-path execution: */
Expr *expr_simple_expr; /* NULL means not a simple expr */
Oid expr_simple_type; /* result type Oid, if simple */
int32 expr_simple_typmod; /* result typmod, if simple */
bool expr_simple_mutable; /* true if simple expr is mutable */
/*
* expr_rwopt tracks whether we have determined that assignment to a
* read/write expanded object (stored in the target_param datum) can be
* optimized by passing it to the expr as a read/write expanded-object
* pointer. If so, expr_rw_param identifies the specific Param that
* should emit a read/write pointer; any others will emit read-only
* pointers.
*/
UPLpgSQL_rwopt expr_rwopt; /* can we apply R/W optimization? */
Param *expr_rw_param; /* read/write Param within expr, if any */
/*
* If the expression was ever determined to be simple, we remember its
* CachedPlanSource and CachedPlan here. If expr_simple_plan_lxid matches
* current LXID, then we hold a refcount on expr_simple_plan in the
* current transaction. Otherwise we need to get one before re-using it.
*/
CachedPlanSource *expr_simple_plansource; /* extracted from "plan" */
CachedPlan *expr_simple_plan; /* extracted from "plan" */
LocalTransactionId expr_simple_plan_lxid;
/*
* if expr is simple AND prepared in current transaction,
* expr_simple_state and expr_simple_in_use are valid. Test validity by
* seeing if expr_simple_lxid matches current LXID. (If not,
* expr_simple_state probably points at garbage!)
*/
ExprState *expr_simple_state; /* eval tree for expr_simple_expr */
bool expr_simple_in_use; /* true if eval tree is active */
LocalTransactionId expr_simple_lxid;
} UPLpgSQL_expr;
/*
* Generic datum array item
*
* UPLpgSQL_datum is the common supertype for UPLpgSQL_var, UPLpgSQL_row,
* UPLpgSQL_rec, and UPLpgSQL_recfield.
*/
typedef struct UPLpgSQL_datum
{
UPLpgSQL_datum_type dtype;
int dno;
} UPLpgSQL_datum;
/*
* Scalar or composite variable
*
* The variants UPLpgSQL_var, UPLpgSQL_row, and UPLpgSQL_rec share these
* fields.
*/
typedef struct UPLpgSQL_variable
{
UPLpgSQL_datum_type dtype;
int dno;
char *refname;
int lineno;
bool isconst;
bool notnull;
UPLpgSQL_expr *default_val;
} UPLpgSQL_variable;
/*
* Scalar variable
*
* DTYPE_VAR and DTYPE_PROMISE datums both use this struct type.
* A PROMISE datum works exactly like a VAR datum for most purposes,
* but if it is read without having previously been assigned to, then
* a special "promised" value is computed and assigned to the datum
* before the read is performed. This technique avoids the overhead of
* computing the variable's value in cases where we expect that many
* functions will never read it.
*/
typedef struct UPLpgSQL_var
{
UPLpgSQL_datum_type dtype;
int dno;
char *refname;
int lineno;
bool isconst;
bool notnull;
UPLpgSQL_expr *default_val;
/* end of UPLpgSQL_variable fields */
UPLpgSQL_type *datatype;
/*
* Variables declared as CURSOR FOR <query> are mostly like ordinary
* scalar variables of type refcursor, but they have these additional
* properties:
*/
UPLpgSQL_expr *cursor_explicit_expr;
int cursor_explicit_argrow;
int cursor_options;
/* Fields below here can change at runtime */
Datum value;
bool isnull;
bool freeval;
/*
* The promise field records which "promised" value to assign if the
* promise must be honored. If it's a normal variable, or the promise has
* been fulfilled, this is UPLPGSQL_PROMISE_NONE.
*/
UPLpgSQL_promise_type promise;
} UPLpgSQL_var;
/*
* Row variable - this represents one or more variables that are listed in an
* INTO clause, FOR-loop targetlist, cursor argument list, etc. We also use
* a row to represent a function's OUT parameters when there's more than one.
*
* Note that there's no way to name the row as such from PL/pgSQL code,
* so many functions don't need to support these.
*
* That also means that there's no real name for the row variable, so we
* conventionally set refname to "(unnamed row)". We could leave it NULL,
* but it's too convenient to be able to assume that refname is valid in
* all variants of UPLpgSQL_variable.
*
* isconst, notnull, and default_val are unsupported (and hence
* always zero/null) for a row. The member variables of a row should have
* been checked to be writable at compile time, so isconst is correctly set
* to false. notnull and default_val aren't applicable.
*/
typedef struct UPLpgSQL_row
{
UPLpgSQL_datum_type dtype;
int dno;
char *refname;
int lineno;
bool isconst;
bool notnull;
UPLpgSQL_expr *default_val;
/* end of UPLpgSQL_variable fields */
/*
* rowtupdesc is only set up if we might need to convert the row into a
* composite datum, which currently only happens for OUT parameters.
* Otherwise it is NULL.
*/
TupleDesc rowtupdesc;
int nfields;
char **fieldnames;
int *varnos;
} UPLpgSQL_row;
/*
* Record variable (any composite type, including RECORD)
*/
typedef struct UPLpgSQL_rec
{
UPLpgSQL_datum_type dtype;
int dno;
char *refname;
int lineno;
bool isconst;
bool notnull;
UPLpgSQL_expr *default_val;
/* end of UPLpgSQL_variable fields */
/*
* Note: for non-RECORD cases, we may from time to time re-look-up the
* composite type, using datatype->origtypname. That can result in
* changing rectypeid.
*/
UPLpgSQL_type *datatype; /* can be NULL, if rectypeid is RECORDOID */
Oid rectypeid; /* declared type of variable */
/* RECFIELDs for this record are chained together for easy access */
int firstfield; /* dno of first RECFIELD, or -1 if none */
/* Fields below here can change at runtime */
/* We always store record variables as "expanded" records */
ExpandedRecordHeader *erh;
} UPLpgSQL_rec;
/*
* Field in record
*/
typedef struct UPLpgSQL_recfield
{
UPLpgSQL_datum_type dtype;
int dno;
/* end of UPLpgSQL_datum fields */
char *fieldname; /* name of field */
int recparentno; /* dno of parent record */
int nextfield; /* dno of next child, or -1 if none */
uint64 rectupledescid; /* record's tupledesc ID as of last lookup */
ExpandedRecordFieldInfo finfo; /* field's attnum and type info */
/* if rectupledescid == INVALID_TUPLEDESC_IDENTIFIER, finfo isn't valid */
} UPLpgSQL_recfield;
/*
* Item in the compilers namespace tree
*/
typedef struct UPLpgSQL_nsitem
{
UPLpgSQL_nsitem_type itemtype;
/*
* For labels, itemno is a value of enum UPLpgSQL_label_type. For other
* itemtypes, itemno is the associated UPLpgSQL_datum's dno.
*/
int itemno;
struct UPLpgSQL_nsitem *prev;
char name[FLEXIBLE_ARRAY_MEMBER]; /* nul-terminated string */
} UPLpgSQL_nsitem;
/*
* Generic execution node
*/
typedef struct UPLpgSQL_stmt
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
/*
* Unique statement ID in this function (starting at 1; 0 is invalid/not
* set). This can be used by a profiler as the index for an array of
* per-statement metrics.
*/
unsigned int stmtid;
} UPLpgSQL_stmt;
/*
* One EXCEPTION condition name
*/
typedef struct UPLpgSQL_condition
{
int sqlerrstate; /* SQLSTATE code, or UPLPGSQL_OTHERS */
char *condname; /* condition name (for debugging) */
struct UPLpgSQL_condition *next;
} UPLpgSQL_condition;
/* This value mustn't match any possible output of MAKE_SQLSTATE() */
#define UPLPGSQL_OTHERS (-1)
/*
* EXCEPTION block
*/
typedef struct UPLpgSQL_exception_block
{
int sqlstate_varno;
int sqlerrm_varno;
List *exc_list; /* List of WHEN clauses */
} UPLpgSQL_exception_block;
/*
* One EXCEPTION ... WHEN clause
*/
typedef struct UPLpgSQL_exception
{
int lineno;
UPLpgSQL_condition *conditions;
List *action; /* List of statements */
} UPLpgSQL_exception;
/*
* Block of statements
*/
typedef struct UPLpgSQL_stmt_block
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
unsigned int stmtid;
char *label;
List *body; /* List of statements */
int n_initvars; /* Length of initvarnos[] */
int *initvarnos; /* dnos of variables declared in this block */
UPLpgSQL_exception_block *exceptions;
int sqlstate_varno; /* dno of SQLSTATE variable, or -1 */
} UPLpgSQL_stmt_block;
/*
* Assign statement
*/
typedef struct UPLpgSQL_stmt_assign
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
unsigned int stmtid;
int varno;
UPLpgSQL_expr *expr;
} UPLpgSQL_stmt_assign;
/*
* PERFORM statement
*/
typedef struct UPLpgSQL_stmt_perform
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
unsigned int stmtid;
UPLpgSQL_expr *expr;
} UPLpgSQL_stmt_perform;
/*
* CALL statement
*/
typedef struct UPLpgSQL_stmt_call
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
unsigned int stmtid;
UPLpgSQL_expr *expr;
bool is_call;
UPLpgSQL_variable *target;
} UPLpgSQL_stmt_call;
/*
* COMMIT statement
*/
typedef struct UPLpgSQL_stmt_commit
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
unsigned int stmtid;
bool chain;
} UPLpgSQL_stmt_commit;
/*
* ROLLBACK statement
*/
typedef struct UPLpgSQL_stmt_rollback
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
unsigned int stmtid;
bool chain;
} UPLpgSQL_stmt_rollback;
/*
* GET DIAGNOSTICS item
*/
typedef struct UPLpgSQL_diag_item
{
UPLpgSQL_getdiag_kind kind; /* id for diagnostic value desired */
int target; /* where to assign it */
} UPLpgSQL_diag_item;
/*
* GET DIAGNOSTICS statement
*/
typedef struct UPLpgSQL_stmt_getdiag
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
unsigned int stmtid;
bool is_stacked; /* STACKED or CURRENT diagnostics area? */
List *diag_items; /* List of UPLpgSQL_diag_item */
} UPLpgSQL_stmt_getdiag;
/*
* IF statement
*/
typedef struct UPLpgSQL_stmt_if
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
unsigned int stmtid;
UPLpgSQL_expr *cond; /* boolean expression for THEN */
List *then_body; /* List of statements */
List *elsif_list; /* List of UPLpgSQL_if_elsif structs */
List *else_body; /* List of statements */
} UPLpgSQL_stmt_if;
/*
* one ELSIF arm of IF statement
*/
typedef struct UPLpgSQL_if_elsif
{
int lineno;
UPLpgSQL_expr *cond; /* boolean expression for this case */
List *stmts; /* List of statements */
} UPLpgSQL_if_elsif;
/*
* CASE statement
*/
typedef struct UPLpgSQL_stmt_case
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
unsigned int stmtid;
UPLpgSQL_expr *t_expr; /* test expression, or NULL if none */
int t_varno; /* var to store test expression value into */
List *case_when_list; /* List of UPLpgSQL_case_when structs */
bool have_else; /* flag needed because list could be empty */
List *else_stmts; /* List of statements */
} UPLpgSQL_stmt_case;
/*
* one arm of CASE statement
*/
typedef struct UPLpgSQL_case_when
{
int lineno;
UPLpgSQL_expr *expr; /* boolean expression for this case */
List *stmts; /* List of statements */
} UPLpgSQL_case_when;
/*
* Unconditional LOOP statement
*/
typedef struct UPLpgSQL_stmt_loop
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
unsigned int stmtid;
char *label;
List *body; /* List of statements */
} UPLpgSQL_stmt_loop;
/*
* WHILE cond LOOP statement (also used for REPEAT UNTIL)
*
* test_at_top = true: WHILE semantics (test before body, default)
* test_at_top = false: REPEAT UNTIL semantics (test after body)
*/
typedef struct UPLpgSQL_stmt_while
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
unsigned int stmtid;
char *label;
UPLpgSQL_expr *cond;
List *body; /* List of statements */
bool test_at_top; /* true=WHILE, false=REPEAT UNTIL */
} UPLpgSQL_stmt_while;
/*
* FOR statement with integer loopvar
*/
typedef struct UPLpgSQL_stmt_fori
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
unsigned int stmtid;
char *label;
UPLpgSQL_var *var;
UPLpgSQL_expr *lower;
UPLpgSQL_expr *upper;
UPLpgSQL_expr *step; /* NULL means default (ie, BY 1) */
int reverse;
List *body; /* List of statements */
} UPLpgSQL_stmt_fori;
/*
* UPLpgSQL_stmt_forq represents a FOR statement running over a SQL query.
* It is the common supertype of UPLpgSQL_stmt_fors, UPLpgSQL_stmt_forc
* and UPLpgSQL_stmt_dynfors.
*/
typedef struct UPLpgSQL_stmt_forq
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
unsigned int stmtid;
char *label;
UPLpgSQL_variable *var; /* Loop variable (record or row) */
List *body; /* List of statements */
} UPLpgSQL_stmt_forq;
/*
* FOR statement running over SELECT
*/
typedef struct UPLpgSQL_stmt_fors
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
unsigned int stmtid;
char *label;
UPLpgSQL_variable *var; /* Loop variable (record or row) */
List *body; /* List of statements */
/* end of fields that must match UPLpgSQL_stmt_forq */
UPLpgSQL_expr *query;
} UPLpgSQL_stmt_fors;
/*
* FOR statement running over cursor
*/
typedef struct UPLpgSQL_stmt_forc
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
unsigned int stmtid;
char *label;
UPLpgSQL_variable *var; /* Loop variable (record or row) */
List *body; /* List of statements */
/* end of fields that must match UPLpgSQL_stmt_forq */
int curvar;
UPLpgSQL_expr *argquery; /* cursor arguments if any */
} UPLpgSQL_stmt_forc;
/*
* FOR statement running over EXECUTE
*/
typedef struct UPLpgSQL_stmt_dynfors
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
unsigned int stmtid;
char *label;
UPLpgSQL_variable *var; /* Loop variable (record or row) */
List *body; /* List of statements */
/* end of fields that must match UPLpgSQL_stmt_forq */
UPLpgSQL_expr *query;
List *params; /* USING expressions */
} UPLpgSQL_stmt_dynfors;
/*
* FOREACH item in array loop
*/
typedef struct UPLpgSQL_stmt_foreach_a
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
unsigned int stmtid;
char *label;
int varno; /* loop target variable */
int slice; /* slice dimension, or 0 */
UPLpgSQL_expr *expr; /* array expression */
List *body; /* List of statements */
} UPLpgSQL_stmt_foreach_a;
/*
* OPEN a curvar
*/
typedef struct UPLpgSQL_stmt_open
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
unsigned int stmtid;
int curvar;
int cursor_options;
UPLpgSQL_expr *argquery;
UPLpgSQL_expr *query;
UPLpgSQL_expr *dynquery;
List *params; /* USING expressions */
} UPLpgSQL_stmt_open;
/*
* FETCH or MOVE statement
*/
typedef struct UPLpgSQL_stmt_fetch
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
unsigned int stmtid;
UPLpgSQL_variable *target; /* target (record or row) */
int curvar; /* cursor variable to fetch from */
FetchDirection direction; /* fetch direction */
long how_many; /* count, if constant (expr is NULL) */
UPLpgSQL_expr *expr; /* count, if expression */
bool is_move; /* is this a fetch or move? */
bool returns_multiple_rows; /* can return more than one row? */
} UPLpgSQL_stmt_fetch;
/*
* CLOSE curvar
*/
typedef struct UPLpgSQL_stmt_close
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
unsigned int stmtid;
int curvar;
} UPLpgSQL_stmt_close;
/*
* EXIT or CONTINUE statement
*/
typedef struct UPLpgSQL_stmt_exit
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
unsigned int stmtid;
bool is_exit; /* Is this an exit or a continue? */
char *label; /* NULL if it's an unlabeled EXIT/CONTINUE */
UPLpgSQL_expr *cond;
} UPLpgSQL_stmt_exit;
/*
* RETURN statement
*/
typedef struct UPLpgSQL_stmt_return
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
unsigned int stmtid;
UPLpgSQL_expr *expr;
int retvarno;
} UPLpgSQL_stmt_return;
/*
* RETURN NEXT statement
*/
typedef struct UPLpgSQL_stmt_return_next
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
unsigned int stmtid;
UPLpgSQL_expr *expr;
int retvarno;
} UPLpgSQL_stmt_return_next;
/*
* RETURN QUERY statement
*/
typedef struct UPLpgSQL_stmt_return_query
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
unsigned int stmtid;
UPLpgSQL_expr *query; /* if static query */
UPLpgSQL_expr *dynquery; /* if dynamic query (RETURN QUERY EXECUTE) */
List *params; /* USING arguments for dynamic query */
} UPLpgSQL_stmt_return_query;
/*
* RAISE statement
*/
typedef struct UPLpgSQL_stmt_raise
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
unsigned int stmtid;
int elog_level;
char *condname; /* condition name, SQLSTATE, or NULL */
char *message; /* old-style message format literal, or NULL */
List *params; /* list of expressions for old-style message */
List *options; /* list of UPLpgSQL_raise_option */
} UPLpgSQL_stmt_raise;
/*
* RAISE statement option
*/
typedef struct UPLpgSQL_raise_option
{
UPLpgSQL_raise_option_type opt_type;
UPLpgSQL_expr *expr;
} UPLpgSQL_raise_option;
/*
* ASSERT statement
*/
typedef struct UPLpgSQL_stmt_assert
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
unsigned int stmtid;
UPLpgSQL_expr *cond;
UPLpgSQL_expr *message;
} UPLpgSQL_stmt_assert;
/*
* Generic SQL statement to execute
*/
typedef struct UPLpgSQL_stmt_execsql
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
unsigned int stmtid;
UPLpgSQL_expr *sqlstmt;
bool mod_stmt; /* is the stmt INSERT/UPDATE/DELETE/MERGE? */
bool mod_stmt_set; /* is mod_stmt valid yet? */
bool into; /* INTO supplied? */
bool strict; /* INTO STRICT flag */
UPLpgSQL_variable *target; /* INTO target (record or row) */
} UPLpgSQL_stmt_execsql;
/*
* Dynamic SQL string to execute
*/
typedef struct UPLpgSQL_stmt_dynexecute
{
UPLpgSQL_stmt_type cmd_type;
int lineno;
unsigned int stmtid;
UPLpgSQL_expr *query; /* string expression */
bool into; /* INTO supplied? */
bool strict; /* INTO STRICT flag */
UPLpgSQL_variable *target; /* INTO target (record or row) */
List *params; /* USING expressions */
} UPLpgSQL_stmt_dynexecute;
/*
* Trigger type
*/
typedef enum UPLpgSQL_trigtype
{
UPLPGSQL_DML_TRIGGER,
UPLPGSQL_EVENT_TRIGGER,
UPLPGSQL_NOT_TRIGGER,
} UPLpgSQL_trigtype;