MCPcopy Create free account
hub / github.com/apache/cloudberry / exec_command_sf_sv

Function exec_command_sf_sv

src/bin/psql/command.c:2385–2485  ·  view source on GitHub ↗

* \sf/\sv -- show a function/view's source code */

Source from the content-addressed store, hash-verified

2383 * \sf/\sv -- show a function/view's source code
2384 */
2385static backslashResult
2386exec_command_sf_sv(PsqlScanState scan_state, bool active_branch,
2387 const char *cmd, bool is_func)
2388{
2389 backslashResult status = PSQL_CMD_SKIP_LINE;
2390
2391 if (active_branch)
2392 {
2393 bool show_linenumbers = (strchr(cmd, '+') != NULL);
2394 PQExpBuffer buf;
2395 char *obj_desc;
2396 Oid obj_oid = InvalidOid;
2397 EditableObjectType eot = is_func ? EditableFunction : EditableView;
2398
2399 buf = createPQExpBuffer();
2400 obj_desc = psql_scan_slash_option(scan_state,
2401 OT_WHOLE_LINE, NULL, true);
2402 if (pset.sversion < (is_func ? 80400 : 70400))
2403 {
2404 char sverbuf[32];
2405
2406 formatPGVersionNumber(pset.sversion, false,
2407 sverbuf, sizeof(sverbuf));
2408 if (is_func)
2409 pg_log_error("The server (version %s) does not support showing function source.",
2410 sverbuf);
2411 else
2412 pg_log_error("The server (version %s) does not support showing view definitions.",
2413 sverbuf);
2414 status = PSQL_CMD_ERROR;
2415 }
2416 else if (!obj_desc)
2417 {
2418 if (is_func)
2419 pg_log_error("function name is required");
2420 else
2421 pg_log_error("view name is required");
2422 status = PSQL_CMD_ERROR;
2423 }
2424 else if (!lookup_object_oid(eot, obj_desc, &obj_oid))
2425 {
2426 /* error already reported */
2427 status = PSQL_CMD_ERROR;
2428 }
2429 else if (!get_create_object_cmd(eot, obj_oid, buf))
2430 {
2431 /* error already reported */
2432 status = PSQL_CMD_ERROR;
2433 }
2434 else
2435 {
2436 FILE *output;
2437 bool is_pager;
2438
2439 /* Select output stream: stdout, pager, or file */
2440 if (pset.queryFout == stdout)
2441 {
2442 /* count lines in function to see if pager is needed */

Callers 1

exec_commandFunction · 0.85

Calls 10

createPQExpBufferFunction · 0.85
formatPGVersionNumberFunction · 0.85
lookup_object_oidFunction · 0.85
get_create_object_cmdFunction · 0.85
count_lines_in_bufFunction · 0.85
PageOutputFunction · 0.85
print_with_linenumbersFunction · 0.85
ClosePagerFunction · 0.85
destroyPQExpBufferFunction · 0.85
ignore_slash_whole_lineFunction · 0.85

Tested by

no test coverage detected