| 3430 | } |
| 3431 | |
| 3432 | static void |
| 3433 | print_function_sqlbody(StringInfo buf, HeapTuple proctup) |
| 3434 | { |
| 3435 | int numargs; |
| 3436 | Oid *argtypes; |
| 3437 | char **argnames; |
| 3438 | char *argmodes; |
| 3439 | deparse_namespace dpns = {0}; |
| 3440 | Datum tmp; |
| 3441 | bool isnull; |
| 3442 | Node *n; |
| 3443 | |
| 3444 | dpns.funcname = pstrdup(NameStr(((Form_pg_proc) GETSTRUCT(proctup))->proname)); |
| 3445 | numargs = get_func_arg_info(proctup, |
| 3446 | &argtypes, &argnames, &argmodes); |
| 3447 | dpns.numargs = numargs; |
| 3448 | dpns.argnames = argnames; |
| 3449 | |
| 3450 | tmp = SysCacheGetAttr(PROCOID, proctup, Anum_pg_proc_prosqlbody, &isnull); |
| 3451 | Assert(!isnull); |
| 3452 | n = stringToNode(TextDatumGetCString(tmp)); |
| 3453 | |
| 3454 | if (IsA(n, List)) |
| 3455 | { |
| 3456 | List *stmts; |
| 3457 | ListCell *lc; |
| 3458 | |
| 3459 | stmts = linitial(castNode(List, n)); |
| 3460 | |
| 3461 | appendStringInfoString(buf, "BEGIN ATOMIC\n"); |
| 3462 | |
| 3463 | foreach(lc, stmts) |
| 3464 | { |
| 3465 | Query *query = lfirst_node(Query, lc); |
| 3466 | |
| 3467 | /* It seems advisable to get at least AccessShareLock on rels */ |
| 3468 | AcquireRewriteLocks(query, false, false); |
| 3469 | get_query_def(query, buf, list_make1(&dpns), NULL, false, |
| 3470 | PRETTYFLAG_INDENT, WRAP_COLUMN_DEFAULT, 1); |
| 3471 | appendStringInfoChar(buf, ';'); |
| 3472 | appendStringInfoChar(buf, '\n'); |
| 3473 | } |
| 3474 | |
| 3475 | appendStringInfoString(buf, "END"); |
| 3476 | } |
| 3477 | else |
| 3478 | { |
| 3479 | Query *query = castNode(Query, n); |
| 3480 | |
| 3481 | /* It seems advisable to get at least AccessShareLock on rels */ |
| 3482 | AcquireRewriteLocks(query, false, false); |
| 3483 | get_query_def(query, buf, list_make1(&dpns), NULL, false, |
| 3484 | 0, WRAP_COLUMN_DEFAULT, 0); |
| 3485 | } |
| 3486 | } |
| 3487 | |
| 3488 | Datum |
| 3489 | pg_get_function_sqlbody(PG_FUNCTION_ARGS) |
no test coverage detected