// Create a new SQL object id. SQLCLI_LIB_FUNC SQLCLI_OBJ_ID* new_SQLCLI_OBJ_ID( Lng32 version, enum SQLOBJ_ID_NAME_MODE mode, const SQLMODULE_ID* module, const char* id, void* handle, const char* charset, Lng32 id_len, Lng32 tag) { SQLCLI_OBJ_ID* x = new SQLCLI_OBJ_ID; init_SQLCLI_OBJ_ID(x, version, mode, module, id, handle, charset, id_len,tag); return x; }
// returns -1, if a transaction is active; 0, otherwise. // Optionally returns the transaction identifier, if transid is passed in. short SqlciEnv::statusTransaction(Int64 * transid) { // if a transaction is active, get the transid by calling the CLI procedure. SQLDESC_ID transid_desc; // added for multi charset module names SQLMODULE_ID module; init_SQLCLI_OBJ_ID(&transid_desc); init_SQLMODULE_ID(&module); module.module_name = 0; transid_desc.module = &module; transid_desc.name_mode = desc_handle; HandleCLIErrorInit(); Lng32 rc = SQL_EXEC_AllocDesc(&transid_desc, 1); HandleCLIError(rc, this); Int64 transid_; rc = SQL_EXEC_SetDescItem(&transid_desc, 1, SQLDESC_VAR_PTR, (Long)&transid_, 0); if (rc) SQL_EXEC_DeallocDesc(&transid_desc); HandleCLIError(rc, this); rc = SQL_EXEC_Xact(SQLTRANS_STATUS, &transid_desc); if (rc == 0) { if (transid) *transid = transid_; // return transID if arg was passed in. rc = -1; // transaction is active. } else rc = 0; SQL_EXEC_DeallocDesc(&transid_desc); return (short)rc; }
Lng32 HSSqTableDef::DescribeColumnNames() { Lng32 entry, len; NAString query; char colName[ComMAX_1_PART_INTERNAL_UTF8_NAME_LEN_IN_BYTES + 2]; HSLogMan *LM = HSLogMan::Instance(); SQLMODULE_ID module; init_SQLMODULE_ID(&module); SQLSTMT_ID *stmt = new(STMTHEAP) SQLSTMT_ID; init_SQLCLI_OBJ_ID(stmt); stmt->module = &module; stmt->name_mode = stmt_handle; SQLDESC_ID *srcDesc = new(STMTHEAP) SQLDESC_ID; init_SQLCLI_OBJ_ID(srcDesc); srcDesc->module = &module; srcDesc->name_mode = desc_handle; SQLDESC_ID *outputDesc = new(STMTHEAP) SQLDESC_ID; init_SQLCLI_OBJ_ID(outputDesc); outputDesc->module = &module; outputDesc->name_mode = desc_handle; // Use the header information from a 'select *' to get the column names. // Note that this works for SJIS and UTF8 since the names returned through // CLI are encoded correctly. retcode_ = setHasSyskeyFlag(); HSHandleError(retcode_); if (hasSyskey_) query = "SELECT SYSKEY, * FROM "; else query = "SELECT * FROM "; if(objActualFormat_ == SQLMP) query += getTableName(tableName_->data(), nameSpace_); else query += getTableName(ansiName_->data(), nameSpace_); retcode_ = SQL_EXEC_ClearDiagnostics(stmt); // to prevent false alarms for statement heap memory allocation "smt" // coverity[leaked_storage] HSHandleError(retcode_); retcode_ = SQL_EXEC_AllocStmt(stmt, 0); HSHandleError(retcode_); retcode_ = SQL_EXEC_AllocDesc(srcDesc, 1); HSHandleError(retcode_); retcode_ = SQL_EXEC_AllocDesc(outputDesc, 4096); HSHandleError(retcode_); retcode_ = SQL_EXEC_SetDescItem(srcDesc, 1, SQLDESC_TYPE_FS, REC_BYTE_V_ANSI, 0); HSHandleError(retcode_); retcode_ = SQL_EXEC_SetDescItem(srcDesc, 1, SQLDESC_VAR_PTR, (Long)query.data(), 0); HSHandleError(retcode_); retcode_ = SQL_EXEC_SetDescItem(srcDesc, 1, SQLDESC_LENGTH, #pragma nowarn(1506) // warning elimination query.length() + 1, 0); #pragma warn(1506) // warning elimination HSHandleError(retcode_); // SQLDESC_CHAR_SET must be the last descriptor item set, otherwise // it may get reset by other calls to SQL_EXEC_SetDescItem(). NAString charSet = ActiveSchemaDB()->getDefaults().getValue(ISO_MAPPING); NAString defCS = ActiveSchemaDB()->getDefaults().getValue(DEFAULT_CHARSET); retcode_ = SQL_EXEC_SetDescItem(srcDesc, 1, SQLDESC_CHAR_SET, SQLCHARSETCODE_UTF8 , 0); HSHandleError(retcode_); // --------------------------------------------------------------------- // Prepare the statement // --------------------------------------------------------------------- SQL_QUERY_COST_INFO query_cost_info; SQL_QUERY_COMPILER_STATS_INFO comp_stats_info; retcode_ = SQL_EXEC_Prepare2(stmt, srcDesc,NULL,0,NULL,&query_cost_info, &comp_stats_info,NULL,0,0); HSHandleError( retcode_); // --------------------------------------------------------------------- // describe the column information into the output descriptor // --------------------------------------------------------------------- retcode_ = SQL_EXEC_DescribeStmt(stmt, 0, outputDesc); HSHandleError(retcode_); retcode_ = SQL_EXEC_GetDescEntryCount(outputDesc, &numCols_); HSHandleError(retcode_); colInfo_ = new(STMTHEAP) HSColumnStruct[numCols_]; for (Int32 i = 0; i < numCols_; i++) { /*== GET COLUMN NAME ==*/ entry = i + 1; retcode_ = SQL_EXEC_GetDescItem(outputDesc, entry, SQLDESC_NAME, 0, colName, sizeof(colName), &len, 0); if ((retcode_ == 0) && (len >= sizeof(colName) )) retcode_ = -1; HSHandleError(retcode_); colName[len] = '\0'; *colInfo_[i].colname = &*colName; /*== GET COLUMN DATATYPE ==*/ retcode_ = SQL_EXEC_GetDescItem(outputDesc, entry, SQLDESC_TYPE_FS, &colInfo_[i].datatype, 0, 0, 0, 0); HSHandleError(retcode_); retcode_ = SQL_EXEC_GetDescItem(outputDesc, entry, SQLDESC_NULLABLE, &colInfo_[i].nullflag, 0, 0, 0, 0); HSHandleError(retcode_); /*== GET COLUMN LENGTH ==*/ retcode_ = SQL_EXEC_GetDescItem(outputDesc, entry, SQLDESC_OCTET_LENGTH, &colInfo_[i].length, 0, 0, 0, 0); HSHandleError(retcode_); // If applicable, get the character set, precision and scale if (DFS2REC::isAnyCharacter(colInfo_[i].datatype)) { retcode_ = SQL_EXEC_GetDescItem(outputDesc, entry, SQLDESC_CHAR_SET, (Lng32*)&colInfo_[i].charset, 0, 0, 0, 0); HSHandleError(retcode_); // UCS2 cols not supported in MODE_SPECIAL_1 or 2 and do not support case insensitivity. retcode_ = SQL_EXEC_GetDescItem(outputDesc, entry, SQLDESC_CASEINSENSITIVE, (Lng32*)&colInfo_[i].caseInsensitive, 0, 0, 0, 0); HSHandleError(retcode_); retcode_ = SQL_EXEC_GetDescItem(outputDesc, entry, SQLDESC_COLLATION, (Lng32*)&colInfo_[i].colCollation, 0, 0, 0, 0); HSHandleError(retcode_); } else if ((colInfo_[i].datatype >= REC_MIN_BINARY && // May be type NUMERIC colInfo_[i].datatype <= REC_MAX_BINARY) // instead of INT || (colInfo_[i].datatype >= REC_MIN_DECIMAL && colInfo_[i].datatype <= REC_MAX_DECIMAL)) { retcode_ = SQL_EXEC_GetDescItem(outputDesc, entry, SQLDESC_PRECISION, &colInfo_[i].precision, 0, 0, 0, 0); HSHandleError(retcode_); retcode_ = SQL_EXEC_GetDescItem(outputDesc, entry, SQLDESC_SCALE, &colInfo_[i].scale, 0, 0, 0, 0); HSHandleError(retcode_); } else if (DFS2REC::isDateTime(colInfo_[i].datatype)) { retcode_ = SQL_EXEC_GetDescItem(outputDesc, entry, SQLDESC_DATETIME_CODE, &colInfo_[i].precision, 0, 0, 0, 0); HSHandleError(retcode_); retcode_ = SQL_EXEC_GetDescItem(outputDesc, entry, SQLDESC_PRECISION, &colInfo_[i].scale, 0, 0, 0, 0); HSHandleError(retcode_); } else if (DFS2REC::isInterval(colInfo_[i].datatype)) { retcode_ = SQL_EXEC_GetDescItem(outputDesc, entry, SQLDESC_INT_LEAD_PREC, &colInfo_[i].precision, 0, 0, 0, 0); HSHandleError(retcode_); retcode_ = SQL_EXEC_GetDescItem(outputDesc, entry, SQLDESC_PRECISION, &colInfo_[i].scale, 0, 0, 0, 0); HSHandleError(retcode_); } else { /* No additional information about column attributes needed */ } if (LM->LogNeeded()) { sprintf(LM->msg, "COLUMN [%s]: (%d, %d, %d, %d, %d, %d)" , colInfo_[i].colname->data() , colInfo_[i].datatype , colInfo_[i].nullflag , colInfo_[i].charset , colInfo_[i].length , colInfo_[i].precision , colInfo_[i].scale ); LM->Log(LM->msg); } } retcode_ = SQL_EXEC_DeallocStmt(stmt); HSHandleError(retcode_); return 0; }