<command>DESCRIBE</command> statement the <literal>DESCRIPTOR</literal>
keyword can be completely omitted if the <literal>INTO</literal> keyword is used:
<programlisting>
EXEC SQL DESCRIBE prepared_statement INTO mysqlda;
</programlisting>
</para>
<procedure>
<para>
The general flow of a program that uses SQLDA is:
</para>
<step><simpara>Prepare a query, and declare a cursor for it.</simpara></step>
<step><simpara>Declare an SQLDA for the result rows.</simpara></step>
<step><simpara>Declare an SQLDA for the input parameters, and initialize them (memory allocation, parameter settings).</simpara></step>
<step><simpara>Open a cursor with the input SQLDA.</simpara></step>
<step><simpara>Fetch rows from the cursor, and store them into an output SQLDA.</simpara></step>
<step><simpara>Read values from the output SQLDA into the host variables (with conversion if necessary).</simpara></step>
<step><simpara>Close the cursor.</simpara></step>
<step><simpara>Free the memory area allocated for the input SQLDA.</simpara></step>
</procedure>
<sect3 id="ecpg-sqlda-descriptors-sqlda">
<title>SQLDA Data Structure</title>
<para>
SQLDA uses three data structure
types: <type>sqlda_t</type>, <type>sqlvar_t</type>,
and <type>struct sqlname</type>.
</para>
<tip>
<para>
PostgreSQL's SQLDA has a similar data structure to the one in
IBM DB2 Universal Database, so some technical information on
DB2's SQLDA could help understanding PostgreSQL's one better.
</para>
</tip>
<sect4 id="ecpg-sqlda-sqlda">
<title>sqlda_t Structure</title>
<para>
The structure type <type>sqlda_t</type> is the type of the
actual SQLDA. It holds one record. And two or
more <type>sqlda_t</type> structures can be connected in a
linked list with the pointer in
the <structfield>desc_next</structfield> field, thus
representing an ordered collection of rows. So, when two or
more rows are fetched, the application can read them by
following the <structfield>desc_next</structfield> pointer in
each <type>sqlda_t</type> node.
</para>
<para>
The definition of <type>sqlda_t</type> is:
<programlisting>
struct sqlda_struct
{
char sqldaid[8];
long sqldabc;
short sqln;
short sqld;
struct sqlda_struct *desc_next;
struct sqlvar_struct sqlvar[1];
};
typedef struct sqlda_struct sqlda_t;
</programlisting>
The meaning of the fields is:
<variablelist>
<varlistentry id="ecpg-sqlda-sqlda-sqldaid">
<term><literal>sqldaid</literal></term>
<listitem>
<para>
It contains the literal string <literal>"SQLDA "</literal>.
</para>
</listitem>
</varlistentry>
<varlistentry id="ecpg-sqlda-sqlda-sqldabc">
<term><literal>sqldabc</literal></term>
<listitem>
<para>
It contains the size of the allocated space in bytes.
</para>
</listitem>
</varlistentry>
<varlistentry id="ecpg-sqlda-sqlda-sqln">
<term><literal>sqln</literal></term>
<listitem>
<para>
It contains the number of input parameters for a parameterized query in
case it's passed into <command>OPEN</command>, <command>DECLARE</command> or
<command>EXECUTE</command> statements using the <literal>USING</literal>
keyword. In case it's used as output of <command>SELECT</command>,
<command>EXECUTE</command> or <command>FETCH</command> statements,
its value is the same as <literal>sqld</literal>
statement
</para>
</listitem>
</varlistentry>
<varlistentry id="ecpg-sqlda-sqlda-sqld">
<term><literal>sqld</literal></term>
<listitem>
<para>
It contains the number of fields in a result set.
</para>
</listitem>
</varlistentry>