SPI_cursor_open_with_args
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 открывает курсор (внутри называемый порталом) для выполнения заданного запроса. Большинство параметров имеют тот же смысл, что и соответствующие параметры функций SPI_prepare_cursor и SPI_cursor_open.
Для разового выполнения запроса эту функцию следует предпочесть SPI_prepare_cursor с последующей SPI_cursor_open. Если же одна и та же команда должна выполняться с самыми разными параметрами, какой вариант окажется быстрее, будет зависеть от стоимости повторного планирования и выигрыша от выбора специализированных планов.
Переданные значения параметров копируются в портал курсора, так что их можно освободить и во время существования курсора.
Эта функция устарела, используйте вместо неё SPI_cursor_parse_open, предоставляющую такую же функциональность, но использующую более современный API для обработки параметров запроса.
Аргументы
const char *nameимя портала, либо
NULL, чтобы имя выбрала системаconst char *commandстрока команды
intnargsчисло входных параметров (
$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') в конце не нужен.boolread_onlytrueдля режима выполнения «только чтение»intcursorOptionsбитовая маска параметров курсора; 0 выбирает поведение по умолчанию
Возвращаемое значение
Указатель на портал, содержащий курсор. Заметьте, что соглашение о возврате ошибок отсутствует; все ошибки выдаются через elog.
SPI_cursor_open_with_args
SPI_cursor_open_with_args — set up a cursor using a query and parameters
Synopsis
Portal SPI_cursor_open_with_args(const char *name, const char *command, intnargs, Oid *argtypes, Datum *values, const char *nulls, boolread_only, intcursorOptions)
Description
SPI_cursor_open_with_args sets up a cursor (internally, a portal) that will execute the specified query. Most of the parameters have the same meanings as the corresponding parameters to SPI_prepare_cursor and SPI_cursor_open.
For one-time query execution, this function should be preferred over SPI_prepare_cursor followed by SPI_cursor_open. 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.
The passed-in parameter data will be copied into the cursor's portal, so it can be freed while the cursor still exists.
This function is now deprecated in favor of SPI_cursor_parse_open, which provides equivalent functionality using a more modern API for handling query parameters.
Arguments
const char *namename for portal, or
NULLto let the system select a nameconst char *commandcommand string
intnargsnumber of input parameters (
$1,$2, etc.)Oid *argtypesan array of length
nargs, containing the OIDs of the data types of the parametersDatum *valuesan array of length
nargs, containing the actual parameter valuesconst char *nullsan array of length
nargs, describing which parameters are nullIf
nullsisNULLthenSPI_cursor_open_with_argsassumes that no parameters are null. Otherwise, each entry of thenullsarray should be' 'if the corresponding parameter value is non-null, or'n'if the corresponding parameter value is null. (In the latter case, the actual value in the correspondingvaluesentry doesn't matter.) Note thatnullsis not a text string, just an array: it does not need a'\0'terminator.boolread_onlytruefor read-only executionintcursorOptionsinteger bit mask of cursor options; zero produces default behavior
Return Value
Pointer to portal containing the cursor. Note there is no error return convention; any error will be reported via elog.