MCPcopy Create free account
hub / github.com/apache/cloudberry / plpgsql_scanner_init

Function plpgsql_scanner_init

src/pl/plpgsql/src/pl_scanner.c:588–635  ·  view source on GitHub ↗

* Called before any actual parsing is done * * Note: the passed "str" must remain valid until plpgsql_scanner_finish(). * Although it is not fed directly to flex, we need the original string * to cite in error messages. */

Source from the content-addressed store, hash-verified

586 * to cite in error messages.
587 */
588void
589plpgsql_scanner_init(const char *str)
590{
591 /*
592 * In GPDB, temporarily disable escape_string_warning, if we're in a QE
593 * node. When we're parsing a PL/pgSQL function, e.g. in a CREATE FUNCTION
594 * command, you should've gotten the same warning from the QD node already.
595 * We could probably disable the warning in QE nodes altogether, not just
596 * in PL/pgSQL, but it can be useful for catching escaping bugs, when
597 * internal queries are dispatched from QD to QEs.
598 */
599 bool save_escape_string_warning = escape_string_warning;
600 PG_TRY();
601 {
602 if (Gp_role == GP_ROLE_EXECUTE)
603 escape_string_warning = false;
604
605 /* Start up the core scanner */
606 yyscanner = scanner_init(str, &core_yy,
607 &ReservedPLKeywords, ReservedPLKeywordTokens);
608
609 if (Gp_role == GP_ROLE_EXECUTE)
610 escape_string_warning = save_escape_string_warning;
611 }
612 PG_CATCH();
613 {
614 if (Gp_role == GP_ROLE_EXECUTE)
615 escape_string_warning = save_escape_string_warning;
616 PG_RE_THROW();
617 }
618 PG_END_TRY();
619
620 /*
621 * scanorig points to the original string, which unlike the scanner's
622 * scanbuf won't be modified on-the-fly by flex. Notice that although
623 * yytext points into scanbuf, we rely on being able to apply locations
624 * (offsets from string start) to scanorig as well.
625 */
626 scanorig = str;
627
628 /* Other setup */
629 plpgsql_IdentifierLookup = IDENTIFIER_LOOKUP_NORMAL;
630 plpgsql_yytoken = 0;
631
632 num_pushbacks = 0;
633
634 location_lineno_init();
635}
636
637/*
638 * Called after parsing is done to clean up after plpgsql_scanner_init()

Callers 2

do_compileFunction · 0.85
plpgsql_compile_inlineFunction · 0.85

Calls 1

location_lineno_initFunction · 0.85

Tested by

no test coverage detected