📄 spi.sgml
字号:
<para> <function>SPI_cursor_close</function> closes a previously created cursor and releases its portal storage. </para> <para> All open cursors are closed automatically at the end of a transaction. <function>SPI_cursor_close</function> need only be invoked if it is desirable to release resources sooner. </para> </refsect1> <refsect1> <title>Arguments</title> <variablelist> <varlistentry> <term><literal>Portal <parameter>portal</parameter></literal></term> <listitem> <para> portal containing the cursor </para> </listitem> </varlistentry> </variablelist> </refsect1></refentry><!-- *********************************************** --><refentry id="spi-spi-saveplan"> <refmeta> <refentrytitle>SPI_saveplan</refentrytitle> </refmeta> <refnamediv> <refname>SPI_saveplan</refname> <refpurpose>save a plan</refpurpose> </refnamediv> <indexterm><primary>SPI_saveplan</primary></indexterm> <refsynopsisdiv><synopsis>void * SPI_saveplan(void * <parameter>plan</parameter>)</synopsis> </refsynopsisdiv> <refsect1> <title>Description</title> <para> <function>SPI_saveplan</function> saves a passed plan (prepared by <function>SPI_prepare</function>) in memory protected from freeing by <function>SPI_finish</function> and by the transaction manager and returns a pointer to the saved plan. This gives you the ability to reuse prepared plans in the subsequent invocations of your procedure in the current session. You may save the pointer returned in a local variable. Always check if this pointer is <symbol>NULL</symbol> or not either when preparing a plan or using an already prepared plan in <function>SPI_execp</function>. </para> </refsect1> <refsect1> <title>Arguments</title> <variablelist> <varlistentry> <term><literal>void * <parameter>plan</parameter></literal></term> <listitem> <para> the plan to be saved </para> </listitem> </varlistentry> </variablelist> </refsect1> <refsect1> <title>Return Value</title> <para> Pointer to the saved plan; <symbol>NULL</symbol> if unsuccessful. On error, <varname>SPI_result</varname> is set thus: <variablelist> <varlistentry> <term><symbol>SPI_ERROR_ARGUMENT</symbol></term> <listitem> <para> if <parameter>plan</parameter> is <symbol>NULL</symbol> </para> </listitem> </varlistentry> <varlistentry> <term><symbol>SPI_ERROR_UNCONNECTED</symbol></term> <listitem> <para> if called from an unconnected procedure </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1> <title>Notes</title> <para> If one of the objects (a table, function, etc.) referenced by the prepared plan is dropped during the session then the results of <function>SPI_execp</function> for this plan will be unpredictable. </para> </refsect1></refentry></sect1><sect1 id="spi-interface-support"> <title>Interface Support Functions</title> <para> The functions described here provide an interface for extracting information from result sets returned by <function>SPI_exec</> and other SPI functions. </para> <para> All functions described in this section may be used by both connected and unconnected procedures. </para><!-- *********************************************** --><refentry id="spi-spi-fname"> <refmeta> <refentrytitle>SPI_fname</refentrytitle> </refmeta> <refnamediv> <refname>SPI_fname</refname> <refpurpose>determine the column name for the specified column number</refpurpose> </refnamediv> <indexterm><primary>SPI_fname</primary></indexterm> <refsynopsisdiv><synopsis>char * SPI_fname(TupleDesc <parameter>rowdesc</parameter>, int <parameter>colnumber</parameter>)</synopsis> </refsynopsisdiv> <refsect1> <title>Description</title> <para> <function>SPI_fname</function> returns the column name of the specified column. (You can use <function>pfree</function> to release the copy of the name when you don't need it anymore.) </para> </refsect1> <refsect1> <title>Arguments</title> <variablelist> <varlistentry> <term><literal>TupleDesc <parameter>rowdesc</parameter></literal></term> <listitem> <para> input row description </para> </listitem> </varlistentry> <varlistentry> <term><literal>int <parameter>colnumber</parameter></literal></term> <listitem> <para> column number (count starts at 1) </para> </listitem> </varlistentry> </variablelist> </refsect1> <refsect1> <title>Return Value</title> <para> The column name; <symbol>NULL</symbol> if <parameter>colnumber</parameter> is out of range. <varname>SPI_result</varname> set to <symbol>SPI_ERROR_NOATTRIBUTE</symbol> on error. </para> </refsect1></refentry><!-- *********************************************** --><refentry id="spi-spi-fnumber"> <refmeta> <refentrytitle>SPI_fnumber</refentrytitle> </refmeta> <refnamediv> <refname>SPI_fnumber</refname> <refpurpose>determine the column number for the specified column name</refpurpose> </refnamediv> <indexterm><primary>SPI_fnumber</primary></indexterm> <refsynopsisdiv><synopsis>int SPI_fnumber(TupleDesc <parameter>rowdesc</parameter>, const char * <parameter>colname</parameter>)</synopsis> </refsynopsisdiv> <refsect1> <title>Description</title> <para> <function>SPI_fnumber</function> returns the column number for the column with the specified name. </para> <para> If <parameter>colname</parameter> refers to a system column (e.g., <literal>oid</>) then the appropriate negative column number will be returned. The caller should be careful to test the return value for exact equality to <symbol>SPI_ERROR_NOATTRIBUTE</symbol> to detect an error; testing the result for less than or equal to 0 is not correct unless system columns should be rejected. </para> </refsect1> <refsect1> <title>Arguments</title> <variablelist> <varlistentry> <term><literal>TupleDesc <parameter>rowdesc</parameter></literal></term> <listitem> <para> input row description </para> </listitem> </varlistentry> <varlistentry> <term><literal>const char * <parameter>colname</parameter></literal></term> <listitem> <para> column name </para> </listitem> </varlistentry> </variablelist> </refsect1> <refsect1> <title>Return Value</title> <para> Column number (count starts at 1), or <symbol>SPI_ERROR_NOATTRIBUTE</symbol> if the named column was not found. </para> </refsect1></refentry><!-- *********************************************** --><refentry id="spi-spi-getvalue"> <refmeta> <refentrytitle>SPI_getvalue</refentrytitle> </refmeta> <refnamediv> <refname>SPI_getvalue</refname> <refpurpose>return the string value of the specified column</refpurpose> </refnamediv> <indexterm><primary>SPI_getvalue</primary></indexterm> <refsynopsisdiv><synopsis>char * SPI_getvalue(HeapTuple <parameter>row</parameter>, TupleDesc <parameter>rowdesc</parameter>, int <parameter>colnumber</parameter>)</synopsis> </refsynopsisdiv> <refsect1> <title>Description</title> <para> <function>SPI_getvalue</function> returns the string representation of the value of the specified column. </para> <para> The result is returned in memory allocated using <function>palloc</function>. (You can use <function>pfree</function> to release the memory when you don't need it anymore.) </para> </refsect1> <refsect1> <title>Arguments</title> <variablelist> <varlistentry> <term><literal>HeapTuple <parameter>row</parameter></literal></term> <listitem> <para> input row to be examined </para> </listitem> </varlistentry> <varlistentry> <term><literal>TupleDesc <parameter>rowdesc</parameter></literal></term> <listitem> <para> input row description </para> </listitem> </varlistentry> <varlistentry> <term><literal>int <parameter>colnumber</parameter></literal></term> <listitem> <para> column number (count starts at 1) </para> </listitem> </varlistentry> </variablelist> </refsect1> <refsect1> <title>Return Value</title> <para> Column value, or <symbol>NULL</symbol> if the column is null, <parameter>colnumber</parameter> is out of range (<varname>SPI_result</varname> is set to <symbol>SPI_ERROR_NOATTRIBUTE</symbol>), or no no output function available (<varname>SPI_result</varname> is set to <symbol>SPI_ERROR_NOOUTFUNC</symbol>). </para> </refsect1></refentry><!-- *********************************************** --><refentry id="spi-spi-getbinval"> <refmeta> <refentrytitle>SPI_getbinval</refentrytitle> </refmeta> <refnamediv> <refname>SPI_getbinval</refname> <refpurpose>return the binary value of the specified column</refpurpose> </refnamediv> <indexterm><primary>SPI_getbinval</primary></indexterm> <refsynopsisdiv><synopsis>Datum SPI_getbinval(HeapTuple <parameter>row</parameter>, TupleDesc <parameter>rowdesc</parameter>, int <parameter>colnumber</parameter>, bool * <parameter>isnull</parameter>)</synopsis> </refsynopsisdiv> <refsect1> <title>Description</title> <para> <function>SPI_getbinval</function> returns the value of the specified column in the internal form (as type <type>Datum</type>). </para> <para> This function does not allocate new space for the datum. In the case of a pass-by-reference data type, the return value will be a pointer into the passed row. </para> </refsect1> <refsect1> <title>Arguments</title> <variablelist> <varlistentry> <term><literal>HeapTuple <parameter>row</parameter></literal></term> <listitem> <para> input row to be examined </para> </listitem> </varlistentry> <varlistentry> <term><literal>TupleDesc <parameter>rowdesc</parameter></literal></term> <listitem> <para> input row description </para> </listitem> </varlistentry> <varlistentry> <term><literal>int <parameter>rownumber</parameter></literal></term> <listitem> <para> column number (count starts at 1) </para> </listitem> </varlistentry> <varlistentry> <term><literal>bool * <parameter>isnull</parameter></literal></term> <listitem> <para> flag for a null value in the column </para> </listitem> </varlistentry> </variablelist> </refsect1> <refsect1> <title>Return Value</title> <para> The binary value of the column is returned. The variable pointed to by <parameter>isnull</parameter> is set to true if the column is null, else to false. </para> <para> <varname>SPI_result</varname> is set to <symbol>SPI_ERROR_NOATTRIBUTE</symbol> on error. </para> </refsect1></refentry><!-- *********************************************** --><refentry id="spi-spi-gettype"> <refmeta> <refentrytitle>SPI_gettype</refentrytitle> </refmeta> <refnamediv> <refname>SPI_gettype</refname> <refpurpose>return the data type name of the specified column</refpurpose> </refnamediv> <indexterm><primary>SPI_gettype</primary></indexterm> <refsynopsisdiv><synopsis>char * SPI_gettype(TupleDesc <parameter>rowdesc</parameter>, int <parameter>colnumber</parameter>)</synopsis> </refsynopsisdiv> <refsect1> <title>Description</title> <para> <function>SPI_gettype</function> returns the data type name of the specified column. (You can use <function>pfree</function> to release the copy of the name when you don't need it anymore.) </para> </refsect1> <refsect1> <title>Arguments</title> <variablelist> <varlistentry> <term><literal>TupleDesc <parameter>rowdesc</parameter></literal></term> <listitem> <para> input row description </para> </listitem> </varlistentry> <varlistentry> <term><literal>int <parameter>colnumber</parameter></literal></term> <listitem> <para> column number (count starts at 1) </para> </listitem> </varlistentry> </variablelist> </refsect1> <refsect1> <title>Return Value</title> <para>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -