Postgresql 中文操作指南
SPI_cursor_parse_open
SPI_cursor_parse_open — 使用查询字符串和参数设置游标
SPI_cursor_parse_open — set up a cursor using a query string and parameters
Synopsis
Portal SPI_cursor_parse_open(const char *name,
const char *command,
const SPIParseOpenOptions * options)
Description
SPI_cursor_parse_open 设置游标(内部,门户),它将执行指定查询字符串。这类似于 SPI_prepare_cursor 后跟 SPI_cursor_open_with_paramlist ,但查询字符串中的参数引用完全通过提供 ParamListInfo 对象来处理。
SPI_cursor_parse_open sets up a cursor (internally, a portal) that will execute the specified query string. This is comparable to SPI_prepare_cursor followed by SPI_cursor_open_with_paramlist, except that parameter references within the query string are handled entirely by supplying a ParamListInfo object.
对于一次性查询执行,此函数应优先于 SPI_prepare_cursor 后跟 SPI_cursor_open_with_paramlist 。如果要使用许多不同的参数执行相同命令,则两种方法都会更快,具体取决于重新规划的成本与定制计划的好处的比较。
For one-time query execution, this function should be preferred over SPI_prepare_cursor followed by SPI_cursor_open_with_paramlist. If the same command is to be executed with many different parameters, either method might be faster, depending on the cost of re-planning versus the benefit of custom plans.
由于总是针对查询使用一次性计划,因此 options→params 对象通常应使用 PARAM_FLAG_CONST 标志标记每个参数。
The options→params object should normally mark each parameter with the PARAM_FLAG_CONST flag, since a one-shot plan is always used for the query.
传入的参数数据将被复制到光标的门户中,因此可在光标仍然存在时释放它。
The passed-in parameter data will be copied into the cursor’s portal, so it can be freed while the cursor still exists.
Arguments
-
const char * _name_
-
name for portal, or NULL to let the system select a name
-
-
const char * _command_
-
command string
-
-
const SPIParseOpenOptions * _options_
-
struct containing optional arguments
-
调用者应始终将整个 options 结构清零,然后填写任何他们想要设置的字段。这样可以确保代码的前向兼容性,因为将来添加到结构中的任何字段都被定义为在为零时向后兼容地工作。当前可用的 options 字段为:
Callers should always zero out the entire options struct, then fill whichever fields they want to set. This ensures forward compatibility of code, since any fields that are added to the struct in future will be defined to behave backwards-compatibly if they are zero. The currently available options fields are:
-
ParamListInfo _params_
-
data structure containing query parameter types and values; NULL if none
-
-
int _cursorOptions_
-
integer bit mask of cursor options; zero produces default behavior
-
-
bool _read_only_
-
true for read-only execution
-