Databases Reference
In-Depth Information
Alternatively, we can include the SQLDA include file and declare an application
variable to make use of the structure:
#include <sqlda.h>
struct sqlda *mysqlda;
Once we define the SQLDA structure, we can use it within SQL statements to
store input or output information as needed. For example, we can use it within a
prepare statement where < sqlstatement > is a variable storing a dynamic SQL
statement:
EXEC SQL PREPARE stmt INTO :*mySqlda FROM < sqlstatement >;
The above statement will prepare and store information into the SQLDA structure
about the dynamic SQL statement specified in the statement. This is equivalent
to the following two statements:
EXEC SQL PREPARE stmt FROM < sqlstatement >;
EXEC DESCRIBE stmt INTO :*mySqlda;
Note that the example above only describes the output rows of a resultset or in
the case of a stored procedure CALL, the INOUT and OUT arguments. To get
information about input parameter markers, you need to add an INPUT INTO
:*myInputSQLDA clause.
Let us try an example and see what is stored in the SQLDA. We include the
sqlca.h header file, declare the mysqlda variable in our code, and define the
variables in Example 4-24.
Example 4-25 Setting up the SQLDA
char test[40];
mysqlda=(struct sqlda*) malloc(SQLDASIZE(2));
mysqlda->sqln=2;
In Example 4-25, we define a buffer named test to store the SQL string that we
will be working with. Also, we allocate an SQLDA structure, which will hold two
SQLVAR elements by using the SQLDASIZE macro, and as required, set a field
named sqln which stores the number of SQLVAR elements needed. We defined
2 SQLVAR structures to be used for our application because we will be working
with at most two table columns.
Next, we assign test to hold our SQL statement. We will be querying for the
product ID (PID) field from the INVENTORY table. We prepare the statement,
using the SQLDA to hold information about the column being returned, and
subsequently print fields of the SQLDA structure.
Search WWH ::




Custom Search