* error context callback to let us supply a call-stack traceback */
| 1543 | * error context callback to let us supply a call-stack traceback |
| 1544 | */ |
| 1545 | static void |
| 1546 | sql_exec_error_callback(void *arg) |
| 1547 | { |
| 1548 | FmgrInfo *flinfo = (FmgrInfo *) arg; |
| 1549 | SQLFunctionCachePtr fcache = (SQLFunctionCachePtr) flinfo->fn_extra; |
| 1550 | int syntaxerrposition; |
| 1551 | |
| 1552 | /* |
| 1553 | * We can do nothing useful if init_sql_fcache() didn't get as far as |
| 1554 | * saving the function name |
| 1555 | */ |
| 1556 | if (fcache == NULL || fcache->fname == NULL) |
| 1557 | return; |
| 1558 | |
| 1559 | /* |
| 1560 | * If there is a syntax error position, convert to internal syntax error |
| 1561 | */ |
| 1562 | syntaxerrposition = geterrposition(); |
| 1563 | if (syntaxerrposition > 0 && fcache->src != NULL) |
| 1564 | { |
| 1565 | errposition(0); |
| 1566 | internalerrposition(syntaxerrposition); |
| 1567 | internalerrquery(fcache->src); |
| 1568 | } |
| 1569 | |
| 1570 | /* |
| 1571 | * Try to determine where in the function we failed. If there is a query |
| 1572 | * with non-null QueryDesc, finger it. (We check this rather than looking |
| 1573 | * for F_EXEC_RUN state, so that errors during ExecutorStart or |
| 1574 | * ExecutorEnd are blamed on the appropriate query; see postquel_start and |
| 1575 | * postquel_end.) |
| 1576 | */ |
| 1577 | if (fcache->func_state) |
| 1578 | { |
| 1579 | execution_state *es; |
| 1580 | int query_num; |
| 1581 | ListCell *lc; |
| 1582 | |
| 1583 | es = NULL; |
| 1584 | query_num = 1; |
| 1585 | foreach(lc, fcache->func_state) |
| 1586 | { |
| 1587 | es = (execution_state *) lfirst(lc); |
| 1588 | while (es) |
| 1589 | { |
| 1590 | if (es->qd) |
| 1591 | { |
| 1592 | errcontext("SQL function \"%s\" statement %d", |
| 1593 | fcache->fname, query_num); |
| 1594 | break; |
| 1595 | } |
| 1596 | es = es->next; |
| 1597 | } |
| 1598 | if (es) |
| 1599 | break; |
| 1600 | query_num++; |
| 1601 | } |
| 1602 | if (es == NULL) |
nothing calls this directly
no test coverage detected