SQLNumParams
SQLNumParams#
SQLNumParams returns the number of parameters in a SQL statement.
Syntax#
SQLRETURN SQLNumParams (
SQLHSTMT stmt,
SQLSMALLINT * parameterCounterPtr );
Arguments#
Data Type | Argument | In/Out | Description |
---|---|---|---|
SQLHSTMT | stmt | Input | Statement handle |
SQLSMALLINT * | parameterCountPtr | Output | Pointer of the number of the parameters |
Return Values#
SQL_SUCCESS
Description#
This function can be called only after SQLPrepare() is called.
If the stmt does not include parameters, SQLNumParams() will set 0 in *parameterCountPtr.
Diagnosis#
SQLSTATE | Description | Comments |
---|---|---|
HY000 | General error |
Related Functions#
SQLBindParameter
SQLDescribeParam
Example#
< Refer to: $ALTIBASE_HOME/sample/SQLCLI/demo_info2.cpp >
SQLPrepare(hstmt, Statement, SQL_NTS);
// Check to see if there are any parameters. If so, process them.
SQLNumParams(hstmt, &NumParams);
if (NumParams) {
// Allocate memory for three arrays. The first holds pointers to buffers in which
// each parameter value will be stored in character form. The second contains the
// length of each buffer. The third contains the length/indicator value for each
// parameter.
PtrArray = (SQLPOINTER *) malloc(NumParams * sizeof(SQLPOINTER));
BufferLenArray = (SQLINTEGER *) malloc(NumParams * sizeof(SQLINTEGER));
LenOrIndArray = (SQLINTEGER *) malloc(NumParams * sizeof(SQLINTEGER));
for (i = 0; i < NumParams; i++) {
// Describe the parameter.
SQLDescribeParam(hstmt, i + 1, &DataType, &ParamSize, &DecimalDigits, &Nullable);
// Call a helper function to allocate a buffer in which to store the parameter
// value in character form. The function determines the size of the buffer from
// the SQL data type and parameter size returned by SQLDescribeParam and returns
// a pointer to the buffer and the length of the buffer.
PtrArray[i] = (char*)malloc(ParamSize);
BufferLenArray[i] = SQL_NTS;
// Bind the memory to the parameter. Assume that we only have input parameters.
SQLBindParameter(hstmt, i + 1, SQL_PARAM_INPUT, SQL_C_CHAR, DataType, ParamSize,
DecimalDigits, PtrArray[i], BufferLenArray[i],
&LenOrIndArray[i]);
// Prompt the user for the value of the parameter and store it in the memory
// allocated earlier. For simplicity, this function does not check the value
// against the information returned by SQLDescribeParam. Instead, the driver does
// this when the statement is executed.
strcpy((char*)PtrArray[i], "AAAAAAA");
BufferLenArray[i] = 7;
}
}