
Dynamic SQL Operations
HP NonStop SQL/MP Programming Manual for C—429847-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)
Содержание NonStop SQL/MP
Страница 4: ......
Страница 14: ...Contents HP NonStop SQL MP Programming Manual for C 429847 008 x ...
Страница 34: ...Introduction HP NonStop SQL MP Programming Manual for C 429847 008 1 8 SQL MP Version Management ...
Страница 60: ...Host Variables HP NonStop SQL MP Programming Manual for C 429847 008 2 26 VARCHAR Data Type ...
Страница 68: ...SQL MP Statements and Directives HP NonStop SQL MP Programming Manual for C 429847 008 3 8 Finding Information ...
Страница 156: ...Explicit Program Compilation HP NonStop SQL MP Programming Manual for C 429847 008 6 40 SQL Program Files ...
Страница 264: ...Dynamic SQL Operations HP NonStop SQL MP Programming Manual for C 429847 008 10 66 Detailed Dynamic SQL Program ...
Страница 294: ...SQL MP Sample Database HP NonStop SQL MP Programming Manual for C 429847 008 A 6 ...
Страница 300: ...Memory Considerations HP NonStop SQL MP Programming Manual for C 429847 008 B 6 Avoiding Memory Stack Overflows ...
Страница 304: ...Maximizing Local Autonomy HP NonStop SQL MP Programming Manual for C 429847 008 C 4 Skipping Unavailable Partitions ...