SQLDescribeParam
SQLDescribeParam#
SQLDescibe returns the SQL data types of the columns related to the parameter marker (?) of the dynamic SQL statements, size, data types, expressions of the corresponding parameter markers, number of decimal values, and the NULLability
Syntax#
SQLRETURN SQLDescribeParam (
SQLHSTMT stmt,
SQLSMALLINT iparam,
SQLSMALLINT * type,
SQLINTEGER * size,
SQLSMALLINT * decimaldigit,
SQLSMALLINT * nullable );
Arguments#
Data Type | Argument | In/Output | Description |
---|---|---|---|
SQLHSTMT | stmt | Input | Statement handle |
SQLSMALLINT | iparam | Input | Order of the parameter marker, starting with 1 |
SQLSMALLINT * | type | Output | SQL data type pointer of the parameter |
SQLINTEGER * | size | Output | SQL data type pointer of the parameter. Column size or expression pointer of the corresponding parameter |
SQLSMALLINT * | decimaldigit | Output | Number of decimal values of the column, expression pointer of the corresponding parameter |
SQLSMALLINT * | nullable | Output | Pointer of the value that shows whether NULL is allowed for the parameter or not |
Return Values#
SQL_SUCCESS
SQL_SUCCESS_WITH_INFO
SQL_INVALID_HANDLE
SQL_ERROR
Description#
Parameter iparam is identified by the number. It is numbered from the left to the right starting with 1.
SQLPrepare() must be called before this function.
Before SQLBindParameter(), SQLDescribeParam() must be called.
types, sizes, decimal digits, and NULLable of the parameter have the following limitations:
-
type: SQL_VARCHAR
-
size: 4000
-
decimaldigit: 0
-
nullable: SQL_NULLABLE_UNKNOWN - The Altibase CLI driver cannot decide whether the parameter allows NULL data.
Diagnosis#
SQLSTATE | Description | Comments |
---|---|---|
07009 | Invalid column number | iparam is out of the entire argument range |
HY010 | Error in function-calling order | Called before SQLPrepare() / SQLExecDirect() |
Related Functions#
SQLExecDirect
SQLNumParams
SQLPrepare
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;
}
}