* 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. */
| 586 | * to cite in error messages. |
| 587 | */ |
| 588 | void |
| 589 | plpgsql_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() |
no test coverage detected