SQLDescribeParam
SQLDescribeParam#
동적 SQL 문의 매개변수 마커(?)와 연관된 칼럼의 SQL 데이터 타입, 크기, 데이터 타입, 해당 매개변수 마커의 표현식, 십진 숫자의 개수, 그리고 nullability를 돌려준다.
구 문#
SQLRETURN SQLDescribeParam (
SQLHSTMT stmt,
SQLSMALLINT iparam,
SQLSMALLINT * type,
SQLINTEGER * size,
SQLSMALLINT * decimaldigit,
SQLSMALLINT * nullable );
인 자#
자료유형 | 인자 | 사용 | 설명 |
---|---|---|---|
SQLHSTMT | stmt | 입력 | 명령문 핸들 |
SQLSMALLINT | iparam | 입력 | 1 부터 시작하는 매개변수 마커 순서 |
SQLSMALLINT * | type | 출력 | 매개변수의 SQL 데이터 타입의 포인터 |
SQLINTEGER * | size | 출력 | 매개변수의 SQL 데이터 타입의 포인터 열의 크기 또는 해당 매개변수 마커의 표현식의 포인터 |
SQLSMALLINT * | decimaldigit | 출력 | 열의 십진 숫자의 개수 또는 해당 매개변수의 표현식의 포인터 |
SQLSMALLINT * | nullable | 출력 | 매개변수가 null이 허용 되는지를 보여주는 값의 포인터 |
결괏값#
SQL_SUCCESS
SQL_SUCCESS_WITH_INFO
SQL_INVALID_HANDLE
SQL_ERROR
설 명#
매개변수 iparam은 번호에 의해 식별되며 왼쪽에서 오른쪽으로, 1부터 번호가 매겨지고, 다른 순서로도 설명될 수 있다.
이 함수를 호출하기 전에 SQLPrepare()를 호출해야 한다.
SQLBindParameter()를 호출하기 전에 일반적으로 SQLDescribeParam()을 호출해야 한다.
임의의 매개변수의 type, size, decimaldigit, nullable은 다음과 같은 제한 조건이 있다.
-
type: SQL_VARCHAR
-
size: 4000
-
decimaldigit: 0
-
nullable: SQL_NULLABLE_UNKNOWN (Altibase CLI 드라이버는 매개 변수가 NULL 값을 허용하는지 결정할 수 없다.)
진 단#
SQLSTATE | 설명 | 부연설명 |
---|---|---|
07009 | 유효하지 않은 열 번호 | iparam 값이 전체 인자의 범위를 벗어남 |
HY010 | 함수호출 순서 오류 | SQLPrepare() / SQLExecDirect() 보다 앞서 호출됨 |
관련 함수#
SQLExecDirect
SQLNumParams
SQLPrepare
예 제#
< $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;
}
}