2
* Program type: Embedded Dynamic SQL
5
* This program demonstrates the reallocation of SQLDA and
6
* the 'describe' statement. After a query is examined with
7
* 'describe', an SQLDA of correct size is reallocated, and some
8
* information is printed about the query: its type (select,
9
* non-select), the number of columns, etc.
10
* The contents of this file are subject to the Interbase Public
11
* License Version 1.0 (the "License"); you may not use this file
12
* except in compliance with the License. You may obtain a copy
13
* of the License at http://www.Inprise.com/IPL.html
15
* Software distributed under the License is distributed on an
16
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
17
* or implied. See the License for the specific language governing
18
* rights and limitations under the License.
20
* The Original Code was created by Inprise Corporation
21
* and its predecessors. Portions created by Inprise Corporation are
22
* Copyright (C) Inprise Corporation.
24
* All Rights Reserved.
25
* Contributor(s): ______________________________________.
34
"SELECT department, mngr_no, location, head_dept \
35
FROM department WHERE head_dept in ('100', '900', '600')";
40
SET DATABASE empdb = "employee.fdb" RUNTIME :Db_name;
43
int main(int argc, char** argv)
49
strcpy(Db_name, argv[1]);
51
strcpy(Db_name, "employee.fdb");
54
WHENEVER SQLERROR GO TO Error;
62
/* Allocate SQLDA of an arbitrary size. */
63
sqlda = (XSQLDA *) malloc(XSQLDA_LENGTH(4));
68
/* Prepare an unknown statement. */
70
PREPARE q INTO SQL DESCRIPTOR sqlda FROM :sel_str;
72
/* Describe the statement. */
74
DESCRIBE q INTO SQL DESCRIPTOR sqlda;
76
/* This is a non-select statement, which can now be executed. */
80
/* If this is a select statement, print more information about it. */
82
printf("Query Type: SELECT\n\n");
84
num_cols = sqlda->sqld;
86
printf("Number of columns selected: %d\n", num_cols);
88
/* Reallocate SQLDA if necessary. */
89
if (sqlda->sqln < sqlda->sqld)
93
sqlda = (XSQLDA *) malloc(XSQLDA_LENGTH(num_cols));
94
sqlda->sqln = num_cols;
95
sqlda->sqld = num_cols;
97
/* Re-describe the statement. */
99
DESCRIBE q INTO SQL DESCRIPTOR sqlda;
101
num_cols = sqlda->sqld;
104
/* List column names, types, and lengths. */
105
for (i = 0; i < num_cols; i++)
107
printf("\nColumn name: %s\n", sqlda->sqlvar[i].sqlname);
108
printf("Column type: %d\n", sqlda->sqlvar[i].sqltype);
109
printf("Column length: %d\n", sqlda->sqlvar[i].sqllen);
122
isc_print_status(gds__status);
123
printf("SQLCODE=%d\n", SQLCODE);