EasyManua.ls Logo

HP NonStop SQL/MP

HP NonStop SQL/MP
331 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Dynamic SQL Operations
HP NonStop SQL/MP Programming Manual for C429847-008
10-45
Detailed Dynamic SQL Program
58 /* ----------------------------------------------------------- */
59 /* SQLDAs and names buffers for input and output variables */
60 /* ----------------------------------------------------------- */
61 sqldaptr sda_i; /* ptr to input sqlda */
62 sqldaptr sda_o; /* ptr to output sqlda */
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; /* ptr to input names buffer */
77 arrayptr cname_o; /* ptr to output names buffer */
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 char *char_ptr; /* for CHAR/VARCHAR */
96 short *smallint_ptr; /* SMALLINT */
97 unsigned short *usmallint_ptr; /* UNSIGNED SMALLINT */
98 long *integer_ptr; /* INTEGER */
99 unsigned long *uinteger_ptr; /* UNSIGNED INTEGER */
100 /* long long *longint_ptr; 64-BIT INTEGER */
101 } in_out_ptrs;
102
103 static short last_query_size = 0; /* num bytes in last query */
104 char datatype_name[50]; /* to display datatype name* /
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
Example 10-8. Detailed Dynamic SQL Program (page 2 of 22)

Table of Contents

Related product manuals