#include "postgres.h" #include "executor/spi.h" #include "utils/builtins.h" #include "catalog/pg_type.h" #ifdef PG_MODULE_MAGIC PG_MODULE_MAGIC; #endif int plantest(); int plantest() { char *command; int ret; int proc; SPI_connect(); //// static SPIPlanPtr plan_getviewrule = NULL; static const char *query_getviewrule = "SELECT * FROM pg_catalog.pg_rewrite WHERE ev_class = $1 AND rulename = $2"; /* * On the first call prepare the plan to lookup pg_rewrite. We read * pg_rewrite over the SPI manager instead of using the syscache to be * checked for read access on pg_rewrite. */ if (plan_getviewrule == NULL) { Oid argtypes[2]; SPIPlanPtr plan; argtypes[0] = OIDOID; argtypes[1] = NAMEOID; plan = SPI_prepare(query_getviewrule, 2, argtypes); if (plan == NULL) elog(ERROR, "SPI_prepare failed for \"%s\"", query_getviewrule); SPI_keepplan(plan); plan_getviewrule = plan; } //// //ret = SPI_exec(command, cnt); //proc = SPI_processed; SPI_finish(); pfree(command); return 0; }
对PostgreSQL的 SPI_prepare 的理解。
最新推荐文章于 2023-12-26 17:20:35 发布