EasyManua.ls Logo

HP NonStop SQL/MP - Page 257

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-59
Detailed Dynamic SQL Program
913 /* ---------------------------------------------------- */
914 } /* switch statement */
915
916 /* ---------------------------------------------- */
917 /* Allocate memory for the data buffer and assign */
918 /* byte address of the data buffer to var_ptr of */
919 /* sqlvar[i]: */
920 /* ---------------------------------------------- */
921 sqlda->sqlvar[i].var_ptr = (long) (malloc (mem_reqd));
922
923 } /* for loop */
924
925 return (0); /* successful buffer allocation */
926 } /* end: setupvarbuffers */
927
928 /* *************************************************** */
929 /* FUNCTION allocate_sqlda */
930 /* This function allocates (using malloc): */
931 /* an sqlda structure with 'num_entries' entries; */
932 /* the function also initializes the sqlda and sqlvars. */
933 /* */
934 /* Return codes: sqlda pointer if successful */
935 /* NULL if failure */
936 /* *************************************************** */
937
938 sqldaptr allocate_sqlda ( int num_entries )
939 /* number of sqlvar_s entries */
940
941 { /* begin allocate_sqlda */
942
943 /* local variables */
944 sqldaptr sqlda; /* pointer to be returned*/
945 int mem_reqd; /* num bytes required to */
946 /* allocate sqlda */
947 short i; /* loop index */
948
949 sqlda = NULL; /* init pointer */
950
951 /* return NULL if 0 entries requested */
952 if (num_entries == 0)
953 return (sqlda);
954
955 /* allocate sqlda */
956 mem_reqd = sizeof( struct SQLDA_TYPE ) +
957 ((num_entries - 1) * sizeof( struct SQLVAR_TYPE ));
958 if ( (sqlda = (sqldaptr) malloc (mem_reqd)) == NULL )
959 /* memory allocation failed */
960 return (sqlda); /* return error condition */
961
962 /* Initialize sqlda; constant sqlda_eye_catcher is defined */
963 /* by the C compiler and is always 2 characters: */
964 strncpy( sqlda -> eye_catcher, SQLDA_EYE_CATCHER, 2);
965
966 sqlda -> num_entries = num_entries;
967
968 /* Initialize ind_ptr to NULL. ind_ptr must always be */
969 /* initialized, even when the program does not handle null */
970 /* values */
971 for (i=0; i < num_entries; i++)
972 sqlda -> sqlvar[i].ind_ptr = NULL;
973
974 return (sqlda); /* successful allocation and init. */
975 } /* end allocate_sqlda */
Example 10-8. Detailed Dynamic SQL Program (page 16 of 22)

Table of Contents

Related product manuals