* executor_errposition * Report an execution-time cursor position, if possible. * * This is expected to be used within an ereport() call. The return value * is a dummy (always 0, in fact). * * The locations stored in parsetrees are byte offsets into the source string. * We have to convert them to 1-based character indexes for reporting to * clients. (We do things this way to avoid unnec
| 953 | * expensive than storing token offsets.) |
| 954 | */ |
| 955 | int |
| 956 | executor_errposition(EState *estate, int location) |
| 957 | { |
| 958 | int pos; |
| 959 | |
| 960 | /* No-op if location was not provided */ |
| 961 | if (location < 0) |
| 962 | return 0; |
| 963 | /* Can't do anything if source text is not available */ |
| 964 | if (estate == NULL || estate->es_sourceText == NULL) |
| 965 | return 0; |
| 966 | /* Convert offset to character number */ |
| 967 | pos = pg_mbstrlen_with_len(estate->es_sourceText, location) + 1; |
| 968 | /* And pass it to the ereport mechanism */ |
| 969 | return errposition(pos); |
| 970 | } |
| 971 | |
| 972 | /* |
| 973 | * Register a shutdown callback in an ExprContext. |
no test coverage detected