HP NonStop SQL/MP Programming Manual page 257

For c
Table of Contents

Advertisement

Dynamic SQL Operations
Example 10-8. Detailed Dynamic SQL Program (page 16 of 22)
913
/* ---------------------------------------------------- */
914
}
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
}
924
925
return (0);
926
}
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
940
941
{ /* begin allocate_sqlda */
942
943
/* local variables */
944
sqldaptr sqlda;
945
int mem_reqd;
946
947
short i;
948
949
sqlda = NULL;
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
958
if ( (sqlda = (sqldaptr) malloc (mem_reqd)) == NULL )
959
960
return (sqlda);
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);
975
} /* end allocate_sqlda */
HP NonStop SQL/MP Programming Manual for C—429847-008
/* switch statement */
/* for loop
*/
/* successful buffer allocation
/* end: setupvarbuffers
/* number of sqlvar_s entries
((num_entries - 1) * sizeof( struct SQLVAR_TYPE ));
10-59
Detailed Dynamic SQL Program
/* pointer to be returned*/
/* num bytes required to */
/* allocate sqlda
/* loop index
/* init pointer
/* memory allocation failed */
/* return error condition
/* successful allocation and init. */
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/

Advertisement

Table of Contents
loading

Table of Contents