|
1 |
| -<!-- $PostgreSQL: pgsql/doc/src/sgml/spi.sgml,v 1.65 2009/08/05 19:31:50 alvherre Exp $ --> |
| 1 | +<!-- $PostgreSQL: pgsql/doc/src/sgml/spi.sgml,v 1.66 2009/11/04 22:26:04 tgl Exp $ --> |
2 | 2 |
|
3 | 3 | <chapter id="spi">
|
4 | 4 | <title>Server Programming Interface</title>
|
@@ -861,7 +861,7 @@ SPIPlanPtr SPI_prepare(const char * <parameter>command</parameter>, int <paramet
|
861 | 861 |
|
862 | 862 | <para>
|
863 | 863 | <function>SPI_prepare</function> creates and returns an execution
|
864 |
| - plan for the specified command but doesn't execute the command. |
| 864 | + plan for the specified command, but doesn't execute the command. |
865 | 865 | This function should only be called from a connected procedure.
|
866 | 866 | </para>
|
867 | 867 |
|
@@ -990,7 +990,7 @@ SPIPlanPtr SPI_prepare_cursor(const char * <parameter>command</parameter>, int <
|
990 | 990 | of the planner's <quote>cursor options</> parameter. This is a bitmask
|
991 | 991 | having the values shown in <filename>nodes/parsenodes.h</filename>
|
992 | 992 | for the <structfield>options</> field of <structname>DeclareCursorStmt</>.
|
993 |
| - <function>SPI_prepare</function> always takes these options as zero. |
| 993 | + <function>SPI_prepare</function> always takes the cursor options as zero. |
994 | 994 | </para>
|
995 | 995 | </refsect1>
|
996 | 996 |
|
@@ -1061,6 +1061,94 @@ SPIPlanPtr SPI_prepare_cursor(const char * <parameter>command</parameter>, int <
|
1061 | 1061 |
|
1062 | 1062 | <!-- *********************************************** -->
|
1063 | 1063 |
|
| 1064 | +<refentry id="spi-spi-prepare-params"> |
| 1065 | + <refmeta> |
| 1066 | + <refentrytitle>SPI_prepare_params</refentrytitle> |
| 1067 | + <manvolnum>3</manvolnum> |
| 1068 | + </refmeta> |
| 1069 | + |
| 1070 | + <refnamediv> |
| 1071 | + <refname>SPI_prepare_params</refname> |
| 1072 | + <refpurpose>prepare a plan for a command, without executing it yet</refpurpose> |
| 1073 | + </refnamediv> |
| 1074 | + |
| 1075 | + <indexterm><primary>SPI_prepare_params</primary></indexterm> |
| 1076 | + |
| 1077 | + <refsynopsisdiv> |
| 1078 | +<synopsis> |
| 1079 | +SPIPlanPtr SPI_prepare_params(const char * <parameter>command</parameter>, |
| 1080 | + ParserSetupHook <parameter>parserSetup</parameter>, |
| 1081 | + void * <parameter>parserSetupArg</parameter>, |
| 1082 | + int <parameter>cursorOptions</parameter>) |
| 1083 | +</synopsis> |
| 1084 | + </refsynopsisdiv> |
| 1085 | + |
| 1086 | + <refsect1> |
| 1087 | + <title>Description</title> |
| 1088 | + |
| 1089 | + <para> |
| 1090 | + <function>SPI_prepare_params</function> creates and returns an execution |
| 1091 | + plan for the specified command, but doesn't execute the command. |
| 1092 | + This function is equivalent to <function>SPI_prepare_cursor</function>, |
| 1093 | + with the addition that the caller can specify parser hook functions |
| 1094 | + to control the parsing of external parameter references. |
| 1095 | + </para> |
| 1096 | + </refsect1> |
| 1097 | + |
| 1098 | + <refsect1> |
| 1099 | + <title>Arguments</title> |
| 1100 | + |
| 1101 | + <variablelist> |
| 1102 | + <varlistentry> |
| 1103 | + <term><literal>const char * <parameter>command</parameter></literal></term> |
| 1104 | + <listitem> |
| 1105 | + <para> |
| 1106 | + command string |
| 1107 | + </para> |
| 1108 | + </listitem> |
| 1109 | + </varlistentry> |
| 1110 | + |
| 1111 | + <varlistentry> |
| 1112 | + <term><literal>ParserSetupHook <parameter>parserSetup</parameter></literal></term> |
| 1113 | + <listitem> |
| 1114 | + <para> |
| 1115 | + Parser hook setup function |
| 1116 | + </para> |
| 1117 | + </listitem> |
| 1118 | + </varlistentry> |
| 1119 | + |
| 1120 | + <varlistentry> |
| 1121 | + <term><literal>void * <parameter>parserSetupArg</parameter></literal></term> |
| 1122 | + <listitem> |
| 1123 | + <para> |
| 1124 | + passthrough argument for <parameter>parserSetup</parameter> |
| 1125 | + </para> |
| 1126 | + </listitem> |
| 1127 | + </varlistentry> |
| 1128 | + |
| 1129 | + <varlistentry> |
| 1130 | + <term><literal>int <parameter>cursorOptions</parameter></literal></term> |
| 1131 | + <listitem> |
| 1132 | + <para> |
| 1133 | + integer bitmask of cursor options; zero produces default behavior |
| 1134 | + </para> |
| 1135 | + </listitem> |
| 1136 | + </varlistentry> |
| 1137 | + </variablelist> |
| 1138 | + </refsect1> |
| 1139 | + |
| 1140 | + <refsect1> |
| 1141 | + <title>Return Value</title> |
| 1142 | + |
| 1143 | + <para> |
| 1144 | + <function>SPI_prepare_params</function> has the same return conventions as |
| 1145 | + <function>SPI_prepare</function>. |
| 1146 | + </para> |
| 1147 | + </refsect1> |
| 1148 | +</refentry> |
| 1149 | + |
| 1150 | +<!-- *********************************************** --> |
| 1151 | + |
1064 | 1152 | <refentry id="spi-spi-getargcount">
|
1065 | 1153 | <refmeta>
|
1066 | 1154 | <refentrytitle>SPI_getargcount</refentrytitle>
|
@@ -1386,14 +1474,100 @@ int SPI_execute_plan(SPIPlanPtr <parameter>plan</parameter>, Datum * <parameter>
|
1386 | 1474 | <function>SPI_execute</function> if successful.
|
1387 | 1475 | </para>
|
1388 | 1476 | </refsect1>
|
| 1477 | +</refentry> |
| 1478 | + |
| 1479 | +<!-- *********************************************** --> |
| 1480 | + |
| 1481 | +<refentry id="spi-spi-execute-plan-with-paramlist"> |
| 1482 | + <refmeta> |
| 1483 | + <refentrytitle>SPI_execute_plan_with_paramlist</refentrytitle> |
| 1484 | + <manvolnum>3</manvolnum> |
| 1485 | + </refmeta> |
| 1486 | + |
| 1487 | + <refnamediv> |
| 1488 | + <refname>SPI_execute_plan_with_paramlist</refname> |
| 1489 | + <refpurpose>execute a plan prepared by <function>SPI_prepare</function></refpurpose> |
| 1490 | + </refnamediv> |
| 1491 | + |
| 1492 | + <indexterm><primary>SPI_execute_plan_with_paramlist</primary></indexterm> |
| 1493 | + |
| 1494 | + <refsynopsisdiv> |
| 1495 | +<synopsis> |
| 1496 | +int SPI_execute_plan_with_paramlist(SPIPlanPtr <parameter>plan</parameter>, |
| 1497 | + ParamListInfo <parameter>params</parameter>, |
| 1498 | + bool <parameter>read_only</parameter>, |
| 1499 | + long <parameter>count</parameter>) |
| 1500 | +</synopsis> |
| 1501 | + </refsynopsisdiv> |
1389 | 1502 |
|
1390 | 1503 | <refsect1>
|
1391 |
| - <title>Notes</title> |
| 1504 | + <title>Description</title> |
1392 | 1505 |
|
1393 | 1506 | <para>
|
1394 |
| - If one of the objects (a table, function, etc.) referenced by the |
1395 |
| - prepared plan is dropped during the session then the result of |
1396 |
| - <function>SPI_execute_plan</function> for this plan will be unpredictable. |
| 1507 | + <function>SPI_execute_plan_with_paramlist</function> executes a plan |
| 1508 | + prepared by <function>SPI_prepare</function>. |
| 1509 | + This function is equivalent to <function>SPI_execute_plan</function> |
| 1510 | + except that information about the parameter values to be passed to the |
| 1511 | + query is presented differently. The <literal>ParamListInfo</> |
| 1512 | + representation can be convenient for passing down values that are |
| 1513 | + already available in that format. It also supports use of dynamic |
| 1514 | + parameter sets via hook functions specified in <literal>ParamListInfo</>. |
| 1515 | + </para> |
| 1516 | + </refsect1> |
| 1517 | + |
| 1518 | + <refsect1> |
| 1519 | + <title>Arguments</title> |
| 1520 | + |
| 1521 | + <variablelist> |
| 1522 | + <varlistentry> |
| 1523 | + <term><literal>SPIPlanPtr <parameter>plan</parameter></literal></term> |
| 1524 | + <listitem> |
| 1525 | + <para> |
| 1526 | + execution plan (returned by <function>SPI_prepare</function>) |
| 1527 | + </para> |
| 1528 | + </listitem> |
| 1529 | + </varlistentry> |
| 1530 | + |
| 1531 | + <varlistentry> |
| 1532 | + <term><literal>ParamListInfo <parameter>params</parameter></literal></term> |
| 1533 | + <listitem> |
| 1534 | + <para> |
| 1535 | + data structure containing parameter types and values; NULL if none |
| 1536 | + </para> |
| 1537 | + </listitem> |
| 1538 | + </varlistentry> |
| 1539 | + |
| 1540 | + <varlistentry> |
| 1541 | + <term><literal>bool <parameter>read_only</parameter></literal></term> |
| 1542 | + <listitem> |
| 1543 | + <para> |
| 1544 | + <literal>true</> for read-only execution |
| 1545 | + </para> |
| 1546 | + </listitem> |
| 1547 | + </varlistentry> |
| 1548 | + |
| 1549 | + <varlistentry> |
| 1550 | + <term><literal>long <parameter>count</parameter></literal></term> |
| 1551 | + <listitem> |
| 1552 | + <para> |
| 1553 | + maximum number of rows to process or return |
| 1554 | + </para> |
| 1555 | + </listitem> |
| 1556 | + </varlistentry> |
| 1557 | + </variablelist> |
| 1558 | + </refsect1> |
| 1559 | + |
| 1560 | + <refsect1> |
| 1561 | + <title>Return Value</title> |
| 1562 | + |
| 1563 | + <para> |
| 1564 | + The return value is the same as for <function>SPI_execute_plan</function>. |
| 1565 | + </para> |
| 1566 | + |
| 1567 | + <para> |
| 1568 | + <varname>SPI_processed</varname> and |
| 1569 | + <varname>SPI_tuptable</varname> are set as in |
| 1570 | + <function>SPI_execute_plan</function> if successful. |
1397 | 1571 | </para>
|
1398 | 1572 | </refsect1>
|
1399 | 1573 | </refentry>
|
@@ -1543,7 +1717,7 @@ Portal SPI_cursor_open(const char * <parameter>name</parameter>, SPIPlanPtr <par
|
1543 | 1717 | </para>
|
1544 | 1718 |
|
1545 | 1719 | <para>
|
1546 |
| - The passed-in data will be copied into the cursor's portal, so it |
| 1720 | + The passed-in parameter data will be copied into the cursor's portal, so it |
1547 | 1721 | can be freed while the cursor still exists.
|
1548 | 1722 | </para>
|
1549 | 1723 | </refsect1>
|
@@ -1667,7 +1841,7 @@ Portal SPI_cursor_open_with_args(const char *<parameter>name</parameter>,
|
1667 | 1841 | </para>
|
1668 | 1842 |
|
1669 | 1843 | <para>
|
1670 |
| - The passed-in data will be copied into the cursor's portal, so it |
| 1844 | + The passed-in parameter data will be copied into the cursor's portal, so it |
1671 | 1845 | can be freed while the cursor still exists.
|
1672 | 1846 | </para>
|
1673 | 1847 | </refsect1>
|
@@ -1770,6 +1944,104 @@ Portal SPI_cursor_open_with_args(const char *<parameter>name</parameter>,
|
1770 | 1944 |
|
1771 | 1945 | <!-- *********************************************** -->
|
1772 | 1946 |
|
| 1947 | +<refentry id="spi-spi-cursor-open-with-paramlist"> |
| 1948 | + <refmeta> |
| 1949 | + <refentrytitle>SPI_cursor_open_with_paramlist</refentrytitle> |
| 1950 | + <manvolnum>3</manvolnum> |
| 1951 | + </refmeta> |
| 1952 | + |
| 1953 | + <refnamediv> |
| 1954 | + <refname>SPI_cursor_open_with_paramlist</refname> |
| 1955 | + <refpurpose>set up a cursor using parameters</refpurpose> |
| 1956 | + </refnamediv> |
| 1957 | + |
| 1958 | + <indexterm><primary>SPI_cursor_open_with_paramlist</primary></indexterm> |
| 1959 | + |
| 1960 | + <refsynopsisdiv> |
| 1961 | +<synopsis> |
| 1962 | +Portal SPI_cursor_open_with_paramlist(const char *<parameter>name</parameter>, |
| 1963 | + SPIPlanPtr <parameter>plan</parameter>, |
| 1964 | + ParamListInfo <parameter>params</parameter>, |
| 1965 | + bool <parameter>read_only</parameter>) |
| 1966 | +</synopsis> |
| 1967 | + </refsynopsisdiv> |
| 1968 | + |
| 1969 | + <refsect1> |
| 1970 | + <title>Description</title> |
| 1971 | + |
| 1972 | + <para> |
| 1973 | + <function>SPI_cursor_open_with_paramlist</function> sets up a cursor |
| 1974 | + (internally, a portal) that will execute a plan prepared by |
| 1975 | + <function>SPI_prepare</function>. |
| 1976 | + This function is equivalent to <function>SPI_cursor_open</function> |
| 1977 | + except that information about the parameter values to be passed to the |
| 1978 | + query is presented differently. The <literal>ParamListInfo</> |
| 1979 | + representation can be convenient for passing down values that are |
| 1980 | + already available in that format. It also supports use of dynamic |
| 1981 | + parameter sets via hook functions specified in <literal>ParamListInfo</>. |
| 1982 | + </para> |
| 1983 | + |
| 1984 | + <para> |
| 1985 | + The passed-in parameter data will be copied into the cursor's portal, so it |
| 1986 | + can be freed while the cursor still exists. |
| 1987 | + </para> |
| 1988 | + </refsect1> |
| 1989 | + |
| 1990 | + <refsect1> |
| 1991 | + <title>Arguments</title> |
| 1992 | + |
| 1993 | + <variablelist> |
| 1994 | + <varlistentry> |
| 1995 | + <term><literal>const char * <parameter>name</parameter></literal></term> |
| 1996 | + <listitem> |
| 1997 | + <para> |
| 1998 | + name for portal, or <symbol>NULL</symbol> to let the system |
| 1999 | + select a name |
| 2000 | + </para> |
| 2001 | + </listitem> |
| 2002 | + </varlistentry> |
| 2003 | + |
| 2004 | + <varlistentry> |
| 2005 | + <term><literal>SPIPlanPtr <parameter>plan</parameter></literal></term> |
| 2006 | + <listitem> |
| 2007 | + <para> |
| 2008 | + execution plan (returned by <function>SPI_prepare</function>) |
| 2009 | + </para> |
| 2010 | + </listitem> |
| 2011 | + </varlistentry> |
| 2012 | + |
| 2013 | + <varlistentry> |
| 2014 | + <term><literal>ParamListInfo <parameter>params</parameter></literal></term> |
| 2015 | + <listitem> |
| 2016 | + <para> |
| 2017 | + data structure containing parameter types and values; NULL if none |
| 2018 | + </para> |
| 2019 | + </listitem> |
| 2020 | + </varlistentry> |
| 2021 | + |
| 2022 | + <varlistentry> |
| 2023 | + <term><literal>bool <parameter>read_only</parameter></literal></term> |
| 2024 | + <listitem> |
| 2025 | + <para> |
| 2026 | + <literal>true</> for read-only execution |
| 2027 | + </para> |
| 2028 | + </listitem> |
| 2029 | + </varlistentry> |
| 2030 | + </variablelist> |
| 2031 | + </refsect1> |
| 2032 | + |
| 2033 | + <refsect1> |
| 2034 | + <title>Return Value</title> |
| 2035 | + |
| 2036 | + <para> |
| 2037 | + Pointer to portal containing the cursor. Note there is no error |
| 2038 | + return convention; any error will be reported via <function>elog</>. |
| 2039 | + </para> |
| 2040 | + </refsect1> |
| 2041 | +</refentry> |
| 2042 | + |
| 2043 | +<!-- *********************************************** --> |
| 2044 | + |
1773 | 2045 | <refentry id="spi-spi-cursor-find">
|
1774 | 2046 | <refmeta>
|
1775 | 2047 | <refentrytitle>SPI_cursor_find</refentrytitle>
|
|
0 commit comments