SPI_cursor_open_with_args — 使用查询和参数设置游标
Portal SPI_cursor_open_with_args(const char *name, const char *command, intnargs, Oid *argtypes, Datum *values, const char *nulls, boolread_only, intcursorOptions)
SPI_cursor_open_with_args 设置一个游标(内部称为 portal),它将执行指定的查询。大多数参数的含义与 SPI_prepare_cursor 和 SPI_cursor_open 的相应参数相同。
对于一次性查询执行,此函数应优先于 SPI_prepare_cursor 后跟 SPI_cursor_open。如果同一个命令要用许多不同的参数执行,则取决于重新规划的成本与自定义计划的好处,这两种方法可能都更快。
传入的参数数据将被复制到游标的 portal 中,因此可以在游标仍然存在时释放这些数据。
此函数现已弃用,推荐使用 SPI_cursor_parse_open,它使用更现代的参数查询处理 API 提供等效功能。
const char * nameportal 的名称,如果为 NULL,则由系统选择名称
const char * commandcommand string
int nargs输入参数的数量($1、$2 等)
Oid * argtypes长度为 nargs 的数组,包含OID参数的数据类型
Datum * values长度为 nargs 的数组,包含实际参数值
const char * nulls长度为 nargs 的数组,描述哪些参数为 null
如果 nulls 为 NULL,则 SPI_cursor_open_with_args 假定没有参数为 null。否则,nulls 数组的每个条目都应该是 ' '(如果相应的参数值非 null),或者 'n'(如果相应的参数值是 null)。(后一种情况,values 条目中的实际值无关紧要。)请注意,nulls 不是文本字符串,只是一个数组:它不需要 '\0' 终止符。
bool read_only只读执行时为 true
int cursorOptions游标选项的整数位掩码;零会产生默认行为
指向包含游标的 portal 的指针。请注意,没有错误返回约定;任何错误都将通过 elog 报告。