EasyManua.ls Logo

HP NonStop SQL/MP - Page 259

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-61
Detailed Dynamic SQL Program
1034 /* ----------------------------------------------------------- */
1035 /* local variables */
1036 /* ----------------------------------------------------------- */
1037 int out_numvars; /* number of output variables */
1038 int in_numvars; /* number of input variables */
1039 unsigned int out_nameslen; /* size of o/p names buffer */
1040 unsigned int in_nameslen; /* size of i/p names buffer */
1041 int status;
1042 unsigned long num_fetches; /* #records fetched */
1043
1044 /* init pointers */
1045 sda_i = sda_o = NULL; /* sqlda pointers */
1046 cname_i = cname_o = NULL; /* names buffer pointers */
1047
1048 /* blank extra byte in host1, host2 */
1049 host1[ max_query_size ] = host2[ max_query_size ] = ' ';
1050
1051 printf("This is DYNAMIC SQL test.\n");
1052 fflush (stdout);
1053
1054 /*****************************************************/
1055 /* Input SQL query from terminal */
1056 /*****************************************************/
1057 enter_input:
1058
1059 /* freeup memory taken by sda_i, sda_o, */
1060 /* and cname_i, cname_o names buffers */
1061 cleanup ();
1062
1063 if ( (status = read_query()) < 0 )
1064 goto exit;
1065
1066 /*****************************************************/
1067 /* BEGIN TRANSACTION */
1068 /*****************************************************/
1069 exec sql begin work ;
1070
1071 /*****************************************************/
1072 /* PREPARE the SQL statement */
1073 /*****************************************************/
1074 exec sql PREPARE S1 from :host1;
1075
1076 if (sqlcode != 0)
1077 { /* display errors/warnings */
1078 printf ("\n"); fflush( stdout );
1079 SQLCADISPLAY ( (int *) &sqlca );
1080 if (sqlcode < 0) /* errors present */
1081 {
1082 exec sql rollback work; /* abort transaction */
1083 goto enter_input; /* try again */
1084 }
1085 }
1086
1087 /***************************************************************/
1088 /* Allocate input and output sqlda and names buffers */
1089 /***************************************************************/
1090 out_numvars = sqlsa.u.prepare.output_num;
1091 out_nameslen = sqlsa.u.prepare.output_names_len;
1092 in_numvars = sqlsa.u.prepare.input_num;
1093 in_nameslen = sqlsa.u.prepare.input_names_len;
1094
Example 10-8. Detailed Dynamic SQL Program (page 18 of 22)

Table of Contents

Related product manuals