Detailed Dynamic Sql Program - HP NonStop SQL/MP Programming Manual

For c
Table of Contents

Advertisement

Dynamic SQL Operations
Example 10-8. Detailed Dynamic SQL Program (page 2 of 22)
58
/* ----------------------------------------------------------- */
59
/* SQLDAs and names buffers for input and output variables
60
/* ----------------------------------------------------------- */
61
sqldaptr sda_i;
62
sqldaptr sda_o;
63
64
/* To give SQL reasonable size information for the names
65
/* buffers, pointers to arrays of 1000 chars are
66
/* currently used. The program will still allocate
67
/* memory just for the required size for the names buffer;
68
/* but such a reference in the embedded SQL statements
69
/* lets SQL get more reasonable sized data (other than
70
/* 1 if a char pointer is used). If enough memory,
71
/* as reported in the SQLSA after the PREPARE statement,
72
/* is allocated for the names buffer, SQL will not use
73
/* (hence, will overwrite) any undesired memory locations.
74
75
typedef char (*arrayptr) [1000];
76
arrayptr cname_i;
77
arrayptr cname_o;
78
79
/* ----------------------------------------------------------- */
80
/* Buffers for storing SQL statements are always blank padded, */
81
/* never null terminated
82
/* ----------------------------------------------------------- */
83
#define max_query_size 512
84
char host1[max_query_size + 1]; /* accepts SQL string
85
char host2[max_query_size + 1]; /* copy of the last SQL stmt
86
87
exec sql end declare section;
88
89
/* ----------------------------------------------------------- */
90
/* The following UNION is defined for pointers to buffers of
91
/* different (SQL) data types. This program does not handle
92
/* FLOAT, DOUBLE PRECISION, or DATETIME
93
/* ----------------------------------------------------------- */
94
union in_out_ptrs_u {
95
96
97
98
99
100
/*
101
} in_out_ptrs;
102
103
static short last_query_size = 0; /* num bytes in last query
104
char datatype_name[50];
105
106
/* ----------------------------------------------------------------- */
107
/* Terminator character when requesting user query (semicolon)
108
/* ----------------------------------------------------------------- */
109
#define QUERY_TERMINATOR (char) ';'
110
/* Cast as char because C treats character constants as type int, */
111
/* and we want to reference it as type char in the function
112
/* prototype
113
114
/* ----------------------------------------------------------------- */
115
/* Terminator character when requesting input param values (EOL)
116
/* ----------------------------------------------------------------- */
117
#define PARAM_TERMINATOR (char) '\n'
118
HP NonStop SQL/MP Programming Manual for C—429847-008
char
*char_ptr;
short
*smallint_ptr;
unsigned short *usmallint_ptr;
long
*integer_ptr;
unsigned long
*uinteger_ptr;
long long
*longint_ptr;
/* ptr to input sqlda
/* ptr to output sqlda
/* ptr to input names buffer
/* ptr to output names buffer
/* for CHAR/VARCHAR
/* SMALLINT
/* UNSIGNED SMALLINT
/* INTEGER
/* UNSIGNED INTEGER
64-BIT INTEGER
/* to display datatype name* /
10-45

Detailed Dynamic SQL Program

*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/

Advertisement

Table of Contents
loading

Table of Contents