SQLRETURN SQL_API SQLDescribeParam(SQLHSTMT StatementHandle, SQLUSMALLINT ParameterNumber, SQLSMALLINT *DataTypePtr, SQLULEN *ParameterSizePtr, SQLSMALLINT *DecimalDigitsPtr, SQLSMALLINT *NullablePtr) { ODBCStmt *stmt = (ODBCStmt *) StatementHandle; ODBCDescRec *rec; #ifdef ODBCDEBUG ODBCLOG("SQLDescribeParam " PTRFMT " %u\n", PTRFMTCAST StatementHandle, (unsigned int) ParameterNumber); #endif if (!isValidStmt(stmt)) return SQL_INVALID_HANDLE; clearStmtErrors(stmt); /* check statement cursor state, query should be prepared or executed */ if (stmt->State == INITED || stmt->State >= EXECUTED0) { /* Function sequence error */ addStmtError(stmt, "HY010", NULL, 0); return SQL_ERROR; } if (ParameterNumber < 1 || ParameterNumber > stmt->ImplParamDescr->sql_desc_count) { /* Invalid descriptor index */ addStmtError(stmt, "07009", NULL, 0); return SQL_ERROR; } rec = &stmt->ImplParamDescr->descRec[ParameterNumber]; if (DataTypePtr) *DataTypePtr = rec->sql_desc_concise_type; if (NullablePtr) *NullablePtr = rec->sql_desc_nullable; /* also see SQLDescribeCol */ if (ParameterSizePtr) *ParameterSizePtr = ODBCLength(rec, SQL_DESC_LENGTH); /* also see SQLDescribeCol */ if (DecimalDigitsPtr) { switch (rec->sql_desc_concise_type) { case SQL_DECIMAL: case SQL_NUMERIC: *DecimalDigitsPtr = rec->sql_desc_scale; break; case SQL_BIT: case SQL_TINYINT: case SQL_SMALLINT: case SQL_INTEGER: case SQL_BIGINT: *DecimalDigitsPtr = 0; break; case SQL_TYPE_TIME: case SQL_TYPE_TIMESTAMP: case SQL_INTERVAL_SECOND: case SQL_INTERVAL_DAY_TO_SECOND: case SQL_INTERVAL_HOUR_TO_SECOND: case SQL_INTERVAL_MINUTE_TO_SECOND: *DecimalDigitsPtr = rec->sql_desc_precision; break; } } return SQL_SUCCESS; }
static SQLRETURN MNDBDescribeCol(ODBCStmt *stmt, SQLUSMALLINT ColumnNumber, SQLCHAR *ColumnName, SQLSMALLINT BufferLength, SQLSMALLINT *NameLengthPtr, SQLSMALLINT *DataTypePtr, SQLULEN *ColumnSizePtr, SQLSMALLINT *DecimalDigitsPtr, SQLSMALLINT *NullablePtr) { ODBCDescRec *rec = NULL; /* check statement cursor state, query should be executed */ if (stmt->State == INITED) { /* Function sequence error */ addStmtError(stmt, "HY010", NULL, 0); return SQL_ERROR; } if (stmt->State == PREPARED0) { /* Prepared statement not a cursor-specification */ addStmtError(stmt, "07005", NULL, 0); return SQL_ERROR; } if (stmt->State == EXECUTED0) { /* Invalid cursor state */ addStmtError(stmt, "24000", NULL, 0); return SQL_ERROR; } if (ColumnNumber < 1 || ColumnNumber > stmt->ImplRowDescr->sql_desc_count) { /* Invalid descriptor index */ addStmtError(stmt, "07009", NULL, 0); return SQL_ERROR; } rec = stmt->ImplRowDescr->descRec + ColumnNumber; /* now copy the data */ copyString(rec->sql_desc_name, strlen((char *) rec->sql_desc_name), ColumnName, BufferLength, NameLengthPtr, SQLSMALLINT, addStmtError, stmt, return SQL_ERROR); if (DataTypePtr) *DataTypePtr = rec->sql_desc_concise_type; /* also see SQLDescribeParam */ if (ColumnSizePtr) { *ColumnSizePtr = ODBCLength(rec, SQL_DESC_LENGTH); if (*ColumnSizePtr == (SQLULEN) SQL_NO_TOTAL) *ColumnSizePtr = 0; } /* also see SQLDescribeParam */ if (DecimalDigitsPtr) { switch (rec->sql_desc_concise_type) { case SQL_DECIMAL: case SQL_NUMERIC: *DecimalDigitsPtr = rec->sql_desc_scale; break; case SQL_BIT: case SQL_TINYINT: case SQL_SMALLINT: case SQL_INTEGER: case SQL_BIGINT: *DecimalDigitsPtr = 0; break; case SQL_TYPE_TIME: case SQL_TYPE_TIMESTAMP: case SQL_INTERVAL_SECOND: case SQL_INTERVAL_DAY_TO_SECOND: case SQL_INTERVAL_HOUR_TO_SECOND: case SQL_INTERVAL_MINUTE_TO_SECOND: *DecimalDigitsPtr = rec->sql_desc_precision; break; default: *DecimalDigitsPtr = 0; break; } } if (NullablePtr) *NullablePtr = rec->sql_desc_nullable; return stmt->Error ? SQL_SUCCESS_WITH_INFO : SQL_SUCCESS; }