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-40
Basic Dynamic SQL Program
62 /* Declare error handling function: */
63 void sql_err()
64 {
65 SQLCADISPLAY ((int *) &sqlca);
66 }
67
68 /* ------------------------------------------------------- */
69
70 /* Declare WHENEVER clause for error checking: */
71 exec sql WHENEVER SQLERROR CALL :sql_err;
72
73 /* ------------------------------------------------------- */
74 void blank_pad(char *buf, size_t size)
75 /* */
76 /* For blank padding character strings to send to SQL */
77 /* */
78
79 {
80 size_t i;
81
82 i = strlen(buf);
83 if (i < size)
84 memset(&buf[i], ' ', size - i);
85 }
86
87 /* ------------------------------------------------------- */
88
89 EXEC SQL BEGIN DECLARE SECTION;
90 void process_and_execute ( char *cmd )
91 {
92 char (*prep_cmd)[ MAXCMD ];
93 /* SQL requires array of char, but we are passing in a */
94 /* pointer to char. We therefore create a pointer to */
95 /* array of char for use by SQL. */
96
97 EXEC SQL END DECLARE SECTION;
98
99 blank_pad (cmd, MAXCMD);
100
101 prep_cmd = cmd;
102
103 exec sql PREPARE dyncmd FROM :*prep_cmd;
104
105 strncpy (osqlda.eye_catcher,SQLDA_EYE_CATCHER, 2);
106
107 osqlda.num_entries = 1;
108
109 /* Initialize ind_ptr to NULL.You must always initialize */
110 /* this field, even when the program is not handling null */
111 /* values. */
112 osqlda.sqlvar[0].ind_ptr = NULL;
113
114 exec sql DESCRIBE dyncmd INTO :osqlda;
115
116 /* SQL tells you what it has to work with; you then */
117 /* communicate what your variable is like to SQL; you */
118 /* might want to look at the data_type field and adjust */
119 /* Here, we're just putting it into a LONG and ignoring */
120 /* scale. */
121
Example 10-7. Basic Dynamic SQL Program (page 2 of 4)

Table of Contents

Related product manuals