@@ -508,6 +508,7 @@ SPI_execute(const char *src, bool read_only, long tcount)
508508
509509 memset (& plan , 0 , sizeof (_SPI_plan ));
510510 plan .magic = _SPI_PLAN_MAGIC ;
511+ plan .parse_mode = RAW_PARSE_DEFAULT ;
511512 plan .cursor_options = CURSOR_OPT_PARALLEL_OK ;
512513
513514 _SPI_prepare_oneshot_plan (src , & plan );
@@ -681,6 +682,7 @@ SPI_execute_with_args(const char *src,
681682
682683 memset (& plan , 0 , sizeof (_SPI_plan ));
683684 plan .magic = _SPI_PLAN_MAGIC ;
685+ plan .parse_mode = RAW_PARSE_DEFAULT ;
684686 plan .cursor_options = CURSOR_OPT_PARALLEL_OK ;
685687 plan .nargs = nargs ;
686688 plan .argtypes = argtypes ;
@@ -726,6 +728,7 @@ SPI_execute_with_receiver(const char *src,
726728
727729 memset (& plan , 0 , sizeof (_SPI_plan ));
728730 plan .magic = _SPI_PLAN_MAGIC ;
731+ plan .parse_mode = RAW_PARSE_DEFAULT ;
729732 plan .cursor_options = CURSOR_OPT_PARALLEL_OK ;
730733 if (params )
731734 {
@@ -768,6 +771,7 @@ SPI_prepare_cursor(const char *src, int nargs, Oid *argtypes,
768771
769772 memset (& plan , 0 , sizeof (_SPI_plan ));
770773 plan .magic = _SPI_PLAN_MAGIC ;
774+ plan .parse_mode = RAW_PARSE_DEFAULT ;
771775 plan .cursor_options = cursorOptions ;
772776 plan .nargs = nargs ;
773777 plan .argtypes = argtypes ;
@@ -784,6 +788,42 @@ SPI_prepare_cursor(const char *src, int nargs, Oid *argtypes,
784788 return result ;
785789}
786790
791+ SPIPlanPtr
792+ SPI_prepare_extended (const char * src ,
793+ const SPIPrepareOptions * options )
794+ {
795+ _SPI_plan plan ;
796+ SPIPlanPtr result ;
797+
798+ if (src == NULL || options == NULL )
799+ {
800+ SPI_result = SPI_ERROR_ARGUMENT ;
801+ return NULL ;
802+ }
803+
804+ SPI_result = _SPI_begin_call (true);
805+ if (SPI_result < 0 )
806+ return NULL ;
807+
808+ memset (& plan , 0 , sizeof (_SPI_plan ));
809+ plan .magic = _SPI_PLAN_MAGIC ;
810+ plan .parse_mode = options -> parseMode ;
811+ plan .cursor_options = options -> cursorOptions ;
812+ plan .nargs = 0 ;
813+ plan .argtypes = NULL ;
814+ plan .parserSetup = options -> parserSetup ;
815+ plan .parserSetupArg = options -> parserSetupArg ;
816+
817+ _SPI_prepare_plan (src , & plan );
818+
819+ /* copy plan to procedure context */
820+ result = _SPI_make_plan_non_temp (& plan );
821+
822+ _SPI_end_call (true);
823+
824+ return result ;
825+ }
826+
787827SPIPlanPtr
788828SPI_prepare_params (const char * src ,
789829 ParserSetupHook parserSetup ,
@@ -805,6 +845,7 @@ SPI_prepare_params(const char *src,
805845
806846 memset (& plan , 0 , sizeof (_SPI_plan ));
807847 plan .magic = _SPI_PLAN_MAGIC ;
848+ plan .parse_mode = RAW_PARSE_DEFAULT ;
808849 plan .cursor_options = cursorOptions ;
809850 plan .nargs = 0 ;
810851 plan .argtypes = NULL ;
@@ -1340,6 +1381,7 @@ SPI_cursor_open_with_args(const char *name,
13401381
13411382 memset (& plan , 0 , sizeof (_SPI_plan ));
13421383 plan .magic = _SPI_PLAN_MAGIC ;
1384+ plan .parse_mode = RAW_PARSE_DEFAULT ;
13431385 plan .cursor_options = cursorOptions ;
13441386 plan .nargs = nargs ;
13451387 plan .argtypes = argtypes ;
@@ -1400,6 +1442,7 @@ SPI_cursor_parse_open_with_paramlist(const char *name,
14001442
14011443 memset (& plan , 0 , sizeof (_SPI_plan ));
14021444 plan .magic = _SPI_PLAN_MAGIC ;
1445+ plan .parse_mode = RAW_PARSE_DEFAULT ;
14031446 plan .cursor_options = cursorOptions ;
14041447 if (params )
14051448 {
@@ -2036,7 +2079,8 @@ spi_printtup(TupleTableSlot *slot, DestReceiver *self)
20362079 * Parse and analyze a querystring.
20372080 *
20382081 * At entry, plan->argtypes and plan->nargs (or alternatively plan->parserSetup
2039- * and plan->parserSetupArg) must be valid, as must plan->cursor_options.
2082+ * and plan->parserSetupArg) must be valid, as must plan->parse_mode and
2083+ * plan->cursor_options.
20402084 *
20412085 * Results are stored into *plan (specifically, plan->plancache_list).
20422086 * Note that the result data is all in CurrentMemoryContext or child contexts
@@ -2063,7 +2107,7 @@ _SPI_prepare_plan(const char *src, SPIPlanPtr plan)
20632107 /*
20642108 * Parse the request string into a list of raw parse trees.
20652109 */
2066- raw_parsetree_list = pg_parse_query (src );
2110+ raw_parsetree_list = raw_parser (src , plan -> parse_mode );
20672111
20682112 /*
20692113 * Do parse analysis and rule rewrite for each raw parsetree, storing the
@@ -2168,7 +2212,7 @@ _SPI_prepare_oneshot_plan(const char *src, SPIPlanPtr plan)
21682212 /*
21692213 * Parse the request string into a list of raw parse trees.
21702214 */
2171- raw_parsetree_list = pg_parse_query (src );
2215+ raw_parsetree_list = raw_parser (src , plan -> parse_mode );
21722216
21732217 /*
21742218 * Construct plancache entries, but don't do parse analysis yet.
@@ -2866,6 +2910,7 @@ _SPI_make_plan_non_temp(SPIPlanPtr plan)
28662910 newplan = (SPIPlanPtr ) palloc0 (sizeof (_SPI_plan ));
28672911 newplan -> magic = _SPI_PLAN_MAGIC ;
28682912 newplan -> plancxt = plancxt ;
2913+ newplan -> parse_mode = plan -> parse_mode ;
28692914 newplan -> cursor_options = plan -> cursor_options ;
28702915 newplan -> nargs = plan -> nargs ;
28712916 if (plan -> nargs > 0 )
@@ -2930,6 +2975,7 @@ _SPI_save_plan(SPIPlanPtr plan)
29302975 newplan = (SPIPlanPtr ) palloc0 (sizeof (_SPI_plan ));
29312976 newplan -> magic = _SPI_PLAN_MAGIC ;
29322977 newplan -> plancxt = plancxt ;
2978+ newplan -> parse_mode = plan -> parse_mode ;
29332979 newplan -> cursor_options = plan -> cursor_options ;
29342980 newplan -> nargs = plan -> nargs ;
29352981 if (plan -> nargs > 0 )
0 commit comments