---------- * exec_stmt_getdiag Put internal PG information into * specified variables. * ---------- */
| 2357 | * ---------- |
| 2358 | */ |
| 2359 | static int |
| 2360 | exec_stmt_getdiag(PLpgSQL_execstate *estate, PLpgSQL_stmt_getdiag *stmt) |
| 2361 | { |
| 2362 | ListCell *lc; |
| 2363 | |
| 2364 | /* |
| 2365 | * GET STACKED DIAGNOSTICS is only valid inside an exception handler. |
| 2366 | * |
| 2367 | * Note: we trust the grammar to have disallowed the relevant item kinds |
| 2368 | * if not is_stacked, otherwise we'd dump core below. |
| 2369 | */ |
| 2370 | if (stmt->is_stacked && estate->cur_error == NULL) |
| 2371 | ereport(ERROR, |
| 2372 | (errcode(ERRCODE_STACKED_DIAGNOSTICS_ACCESSED_WITHOUT_ACTIVE_HANDLER), |
| 2373 | errmsg("GET STACKED DIAGNOSTICS cannot be used outside an exception handler"))); |
| 2374 | |
| 2375 | foreach(lc, stmt->diag_items) |
| 2376 | { |
| 2377 | PLpgSQL_diag_item *diag_item = (PLpgSQL_diag_item *) lfirst(lc); |
| 2378 | PLpgSQL_datum *var = estate->datums[diag_item->target]; |
| 2379 | |
| 2380 | switch (diag_item->kind) |
| 2381 | { |
| 2382 | case PLPGSQL_GETDIAG_ROW_COUNT: |
| 2383 | exec_assign_value(estate, var, |
| 2384 | UInt64GetDatum(estate->eval_processed), |
| 2385 | false, INT8OID, -1); |
| 2386 | break; |
| 2387 | |
| 2388 | case PLPGSQL_GETDIAG_ERROR_CONTEXT: |
| 2389 | exec_assign_c_string(estate, var, |
| 2390 | estate->cur_error->context); |
| 2391 | break; |
| 2392 | |
| 2393 | case PLPGSQL_GETDIAG_ERROR_DETAIL: |
| 2394 | exec_assign_c_string(estate, var, |
| 2395 | estate->cur_error->detail); |
| 2396 | break; |
| 2397 | |
| 2398 | case PLPGSQL_GETDIAG_ERROR_HINT: |
| 2399 | exec_assign_c_string(estate, var, |
| 2400 | estate->cur_error->hint); |
| 2401 | break; |
| 2402 | |
| 2403 | case PLPGSQL_GETDIAG_RETURNED_SQLSTATE: |
| 2404 | exec_assign_c_string(estate, var, |
| 2405 | unpack_sql_state(estate->cur_error->sqlerrcode)); |
| 2406 | break; |
| 2407 | |
| 2408 | case PLPGSQL_GETDIAG_COLUMN_NAME: |
| 2409 | exec_assign_c_string(estate, var, |
| 2410 | estate->cur_error->column_name); |
| 2411 | break; |
| 2412 | |
| 2413 | case PLPGSQL_GETDIAG_CONSTRAINT_NAME: |
| 2414 | exec_assign_c_string(estate, var, |
| 2415 | estate->cur_error->constraint_name); |
| 2416 | break; |
no test coverage detected