📄 pl_funcs.c
字号:
case PLPGSQL_STMT_LOOP: dump_loop((PLpgSQL_stmt_loop *) stmt); break; case PLPGSQL_STMT_WHILE: dump_while((PLpgSQL_stmt_while *) stmt); break; case PLPGSQL_STMT_FORI: dump_fori((PLpgSQL_stmt_fori *) stmt); break; case PLPGSQL_STMT_FORS: dump_fors((PLpgSQL_stmt_fors *) stmt); break; case PLPGSQL_STMT_SELECT: dump_select((PLpgSQL_stmt_select *) stmt); break; case PLPGSQL_STMT_EXIT: dump_exit((PLpgSQL_stmt_exit *) stmt); break; case PLPGSQL_STMT_RETURN: dump_return((PLpgSQL_stmt_return *) stmt); break; case PLPGSQL_STMT_RETURN_NEXT: dump_return_next((PLpgSQL_stmt_return_next *) stmt); break; case PLPGSQL_STMT_RAISE: dump_raise((PLpgSQL_stmt_raise *) stmt); break; case PLPGSQL_STMT_EXECSQL: dump_execsql((PLpgSQL_stmt_execsql *) stmt); break; case PLPGSQL_STMT_DYNEXECUTE: dump_dynexecute((PLpgSQL_stmt_dynexecute *) stmt); break; case PLPGSQL_STMT_DYNFORS: dump_dynfors((PLpgSQL_stmt_dynfors *) stmt); break; case PLPGSQL_STMT_GETDIAG: dump_getdiag((PLpgSQL_stmt_getdiag *) stmt); break; case PLPGSQL_STMT_OPEN: dump_open((PLpgSQL_stmt_open *) stmt); break; case PLPGSQL_STMT_FETCH: dump_fetch((PLpgSQL_stmt_fetch *) stmt); break; case PLPGSQL_STMT_CLOSE: dump_close((PLpgSQL_stmt_close *) stmt); break; case PLPGSQL_STMT_PERFORM: dump_perform((PLpgSQL_stmt_perform *) stmt); break; default: elog(ERROR, "unrecognized cmd_type: %d", stmt->cmd_type); break; }}static voiddump_block(PLpgSQL_stmt_block * block){ int i; char *name; if (block->label == NULL) name = "*unnamed*"; else name = block->label; dump_ind(); printf("BLOCK <<%s>>\n", name); dump_indent += 2; for (i = 0; i < block->body->stmts_used; i++) dump_stmt((PLpgSQL_stmt *) (block->body->stmts[i])); dump_indent -= 2; dump_ind(); printf(" END -- %s\n", name);}static voiddump_assign(PLpgSQL_stmt_assign * stmt){ dump_ind(); printf("ASSIGN var %d := ", stmt->varno); dump_expr(stmt->expr); printf("\n");}static voiddump_if(PLpgSQL_stmt_if * stmt){ int i; dump_ind(); printf("IF "); dump_expr(stmt->cond); printf(" THEN\n"); dump_indent += 2; for (i = 0; i < stmt->true_body->stmts_used; i++) dump_stmt((PLpgSQL_stmt *) (stmt->true_body->stmts[i])); dump_indent -= 2; dump_ind(); printf(" ELSE\n"); dump_indent += 2; for (i = 0; i < stmt->false_body->stmts_used; i++) dump_stmt((PLpgSQL_stmt *) (stmt->false_body->stmts[i])); dump_indent -= 2; dump_ind(); printf(" ENDIF\n");}static voiddump_loop(PLpgSQL_stmt_loop * stmt){ int i; dump_ind(); printf("LOOP\n"); dump_indent += 2; for (i = 0; i < stmt->body->stmts_used; i++) dump_stmt((PLpgSQL_stmt *) (stmt->body->stmts[i])); dump_indent -= 2; dump_ind(); printf(" ENDLOOP\n");}static voiddump_while(PLpgSQL_stmt_while * stmt){ int i; dump_ind(); printf("WHILE "); dump_expr(stmt->cond); printf("\n"); dump_indent += 2; for (i = 0; i < stmt->body->stmts_used; i++) dump_stmt((PLpgSQL_stmt *) (stmt->body->stmts[i])); dump_indent -= 2; dump_ind(); printf(" ENDWHILE\n");}static voiddump_fori(PLpgSQL_stmt_fori * stmt){ int i; dump_ind(); printf("FORI %s %s\n", stmt->var->refname, (stmt->reverse) ? "REVERSE" : "NORMAL"); dump_indent += 2; dump_ind(); printf(" lower = "); dump_expr(stmt->lower); printf("\n"); dump_ind(); printf(" upper = "); dump_expr(stmt->upper); printf("\n"); for (i = 0; i < stmt->body->stmts_used; i++) dump_stmt((PLpgSQL_stmt *) (stmt->body->stmts[i])); dump_indent -= 2; dump_ind(); printf(" ENDFORI\n");}static voiddump_fors(PLpgSQL_stmt_fors * stmt){ int i; dump_ind(); printf("FORS %s ", (stmt->rec != NULL) ? stmt->rec->refname : stmt->row->refname); dump_expr(stmt->query); printf("\n"); dump_indent += 2; for (i = 0; i < stmt->body->stmts_used; i++) dump_stmt((PLpgSQL_stmt *) (stmt->body->stmts[i])); dump_indent -= 2; dump_ind(); printf(" ENDFORS\n");}static voiddump_select(PLpgSQL_stmt_select * stmt){ dump_ind(); printf("SELECT "); dump_expr(stmt->query); printf("\n"); dump_indent += 2; if (stmt->rec != NULL) { dump_ind(); printf(" target = %d %s\n", stmt->rec->recno, stmt->rec->refname); } if (stmt->row != NULL) { dump_ind(); printf(" target = %d %s\n", stmt->row->rowno, stmt->row->refname); } dump_indent -= 2;}static voiddump_open(PLpgSQL_stmt_open * stmt){ dump_ind(); printf("OPEN curvar=%d\n", stmt->curvar); dump_indent += 2; if (stmt->argquery != NULL) { dump_ind(); printf(" arguments = '"); dump_expr(stmt->argquery); printf("'\n"); } if (stmt->query != NULL) { dump_ind(); printf(" query = '"); dump_expr(stmt->query); printf("'\n"); } if (stmt->dynquery != NULL) { dump_ind(); printf(" execute = '"); dump_expr(stmt->dynquery); printf("'\n"); } dump_indent -= 2;}static voiddump_fetch(PLpgSQL_stmt_fetch * stmt){ dump_ind(); printf("FETCH curvar=%d\n", stmt->curvar); dump_indent += 2; if (stmt->rec != NULL) { dump_ind(); printf(" target = %d %s\n", stmt->rec->recno, stmt->rec->refname); } if (stmt->row != NULL) { dump_ind(); printf(" target = %d %s\n", stmt->row->rowno, stmt->row->refname); } dump_indent -= 2;}static voiddump_close(PLpgSQL_stmt_close * stmt){ dump_ind(); printf("CLOSE curvar=%d\n", stmt->curvar);}static voiddump_perform(PLpgSQL_stmt_perform * stmt){ dump_ind(); printf("PERFORM expr = "); dump_expr(stmt->expr); printf("\n");}static voiddump_exit(PLpgSQL_stmt_exit * stmt){ dump_ind(); printf("EXIT lbl='%s'", stmt->label); if (stmt->cond != NULL) { printf(" WHEN "); dump_expr(stmt->cond); } printf("\n");}static voiddump_return(PLpgSQL_stmt_return * stmt){ dump_ind(); printf("RETURN "); if (stmt->retrecno >= 0) printf("record %d", stmt->retrecno); else if (stmt->retrowno >= 0) printf("row %d", stmt->retrowno); else if (stmt->expr == NULL) printf("NULL"); else dump_expr(stmt->expr); printf("\n");}static voiddump_return_next(PLpgSQL_stmt_return_next * stmt){ dump_ind(); printf("RETURN NEXT "); if (stmt->rec != NULL) printf("target = %d %s\n", stmt->rec->recno, stmt->rec->refname); else if (stmt->row != NULL) printf("target = %d %s\n", stmt->row->rowno, stmt->row->refname); else if (stmt->expr != NULL) dump_expr(stmt->expr); printf("\n");}static voiddump_raise(PLpgSQL_stmt_raise * stmt){ int i; dump_ind(); printf("RAISE '%s'", stmt->message); for (i = 0; i < stmt->nparams; i++) printf(" %d", stmt->params[i]); printf("\n");}static voiddump_execsql(PLpgSQL_stmt_execsql * stmt){ dump_ind(); printf("EXECSQL "); dump_expr(stmt->sqlstmt); printf("\n");}static voiddump_dynexecute(PLpgSQL_stmt_dynexecute * stmt){ dump_ind(); printf("EXECUTE "); dump_expr(stmt->query); printf("\n");}static voiddump_dynfors(PLpgSQL_stmt_dynfors * stmt){ int i; dump_ind(); printf("FORS %s EXECUTE ", (stmt->rec != NULL) ? stmt->rec->refname : stmt->row->refname); dump_expr(stmt->query); printf("\n"); dump_indent += 2; for (i = 0; i < stmt->body->stmts_used; i++) dump_stmt((PLpgSQL_stmt *) (stmt->body->stmts[i])); dump_indent -= 2; dump_ind(); printf(" ENDFORS\n");}static voiddump_getdiag(PLpgSQL_stmt_getdiag * stmt){ int i; dump_ind(); printf("GET DIAGNOSTICS "); for (i = 0; i < stmt->ndtitems; i++) { PLpgSQL_diag_item *dtitem = &stmt->dtitems[i]; if (i != 0) printf(", "); printf("{var %d} = ", dtitem->target); switch (dtitem->item) { case PLPGSQL_GETDIAG_ROW_COUNT: printf("ROW_COUNT"); break; case PLPGSQL_GETDIAG_RESULT_OID: printf("RESULT_OID"); break; default: printf("???"); break; } } printf("\n");}static voiddump_expr(PLpgSQL_expr * expr){ int i; printf("'%s", expr->query); if (expr->nparams > 0) { printf(" {"); for (i = 0; i < expr->nparams; i++) { if (i > 0) printf(", "); printf("$%d=%d", i + 1, expr->params[i]); } printf("}"); } printf("'");}voidplpgsql_dumptree(PLpgSQL_function * func){ int i; PLpgSQL_datum *d; printf("\nExecution tree of successfully compiled PL/pgSQL function %s:\n", func->fn_name); printf("\nFunctions data area:\n"); for (i = 0; i < func->ndatums; i++) { d = func->datums[i]; printf(" entry %d: ", i); switch (d->dtype) { case PLPGSQL_DTYPE_VAR: { PLpgSQL_var *var = (PLpgSQL_var *) d; printf("VAR %-16s type %s (typoid %u) atttypmod %d\n", var->refname, var->datatype->typname, var->datatype->typoid, var->datatype->atttypmod); if (var->isconst) printf(" CONSTANT\n"); if (var->notnull) printf(" NOT NULL\n"); if (var->default_val != NULL) { printf(" DEFAULT "); dump_expr(var->default_val); printf("\n"); } if (var->cursor_explicit_expr != NULL) { if (var->cursor_explicit_argrow >= 0) printf(" CURSOR argument row %d\n", var->cursor_explicit_argrow); printf(" CURSOR IS "); dump_expr(var->cursor_explicit_expr); printf("\n"); } } break; case PLPGSQL_DTYPE_ROW: { PLpgSQL_row *row = (PLpgSQL_row *) d; int i; printf("ROW %-16s fields", row->refname); for (i = 0; i < row->nfields; i++) { if (row->fieldnames[i]) printf(" %s=var %d", row->fieldnames[i], row->varnos[i]); } printf("\n"); } break; case PLPGSQL_DTYPE_REC: printf("REC %s\n", ((PLpgSQL_rec *) d)->refname); break; case PLPGSQL_DTYPE_RECFIELD: printf("RECFIELD %-16s of REC %d\n", ((PLpgSQL_recfield *) d)->fieldname, ((PLpgSQL_recfield *) d)->recparentno); break; case PLPGSQL_DTYPE_ARRAYELEM: printf("ARRAYELEM of VAR %d subscript ", ((PLpgSQL_arrayelem *) d)->arrayparentno); dump_expr(((PLpgSQL_arrayelem *) d)->subscript); printf("\n"); break; case PLPGSQL_DTYPE_TRIGARG: printf("TRIGARG "); dump_expr(((PLpgSQL_trigarg *) d)->argnum); printf("\n"); break; default: printf("??? unknown data type %d\n", d->dtype); } } printf("\nFunctions statements:\n"); dump_indent = 0; printf("%3d:", func->action->lineno); dump_block(func->action); printf("\nEnd of execution tree of function %s\n\n", func->fn_name);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -