SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
C Sample Programs
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
A-13
Using SQL Descriptor Areas Without DESCRIBE
/* Copy statement with input variables. */
strcpy(hv_sql_stmt, "UPDATE samdbcat.persnl.employee"
" SET salary = salary * 1.1"
" WHERE jobcode = CAST(? AS NUMERIC(4) UNSIGNED)"
" AND last_name = ?");
/* Allocate the descriptor area for input parameters. */
desc_max=2;
EXEC SQL ALLOCATE DESCRIPTOR 'in_sqlda' WITH MAX :desc_max;
/* Prepare the statement. */
EXEC SQL PREPARE sqlstmt FROM :hv_sql_stmt;
/* Initialize the input parameters in the WHERE clause. */
printf("Enter the jobcode: ");
scanf("%hu", &in_jobcode);
printf("Enter the last name: ");
scanf("%s", &in_last_name);
/* Set the values for the jobcode input parameter. */
desc_value = 1;
desc_type = -502; /* Smallint unsigned */
desc_precision = 4;
desc_scale = 0;
EXEC SQL SET DESCRIPTOR 'in_sqlda' VALUE :desc_value
TYPE = :desc_type,
PRECISION = :desc_precision,
SCALE = :desc_scale,
VARIABLE_DATA = :in_jobcode;
/* Set the values for the last name input parameter. */
desc_value = 2;
desc_type = 12; /* character varying */
desc_length = 20;
EXEC SQL SET DESCRIPTOR 'in_sqlda' VALUE :desc_value
TYPE = :desc_type,
LENGTH = :desc_length,
VARIABLE_DATA = :in_last_name;
EXEC SQL BEGIN WORK;
/* Execute the prepared statement using */
/* the SQL descriptor areas. */
EXEC SQL EXECUTE sqlstmt
USING SQL DESCRIPTOR 'in_sqlda';
Example A-5. Using SQL Descriptor Areas Without DESCRIBE (page2of3)