short SqlciRWInterfaceExecutor::open(SqlciEnv * sqlci_env) { short rc; #ifdef _DEBUG if (getenv("SHOW_RW_STATE")) { char buf[40]; strcpy(buf, "OPEN_"); cout << "State " << buf << endl; } #endif // close cursor. TBD: add SqlCmd::close() call to do this. // Ignore error, stmt may already be closed. SQL_EXEC_CloseStmt(prepStmt_->getStmt()); SQL_EXEC_ClearDiagnostics(prepStmt_->getStmt()); // open the stmt rc = SqlCmd::doExec(sqlci_env, prepStmt_->getStmt(), prepStmt_, numUsingParams_, usingParams_); currCount_ = 0; cursorOpened_ = TRUE; return rc; }
Lng32 executeUsingString(const char *s, Lng32 len) { if (!initialized_) { return -9999; } Lng32 result = 0; if (!result) result = SQL_EXEC_ClearDiagnostics(NULL); if (!result) result = SQL_EXEC_SetDescItem(&inDesc_, 1, SQLDESC_TYPE, (Lng32) SQLTYPECODE_CHAR, 0); if (!result) result = SQL_EXEC_SetDescItem(&inDesc_, 1, SQLDESC_LENGTH, (Lng32) len, 0); if (!result) result = SQL_EXEC_SetDescItem(&inDesc_, 1, SQLDESC_VAR_PTR, (Long) s, 0); if (!result) result = SQL_EXEC_ExecClose(&stmtId_, &inDesc_, 0); SQL_ERROR_HANDLER(result); return result; }
// ----------------------------------------------------------------------- // getUserNameFromUserID // // Reads the USERS table to get the user name associated with the passed // in userID // // <userID> Int32 In // is the numeric ID to be mapped to a name. // // <userName> char * In // passes back the name that the numeric ID mapped to. If the ID does // not map to a name, the ASCII equivalent of the ID is passed back. // // <maxLen> Int32 In // is the size of <authName>. // // <actualLen> Int32 & Out // is the size of the auth name in the table. If larger than <maxLen>, // caller needs to supply a larger buffer. // // Returns: // FEOK -- Found. User name written to userName. Length // returned in actualLen. // FENOTFOUND -- Not found // FEBUFTOOSMALL -- Found but output buffer is too small. Required // length returned in actualLen. // Other -- Unexpected error // ----------------------------------------------------------------------- Int16 ComUser::getUserNameFromUserID(Int32 userID, char *userName, Int32 maxLen, Int32 &actualLen) { Int16 result = FEOK; actualLen = 0; Int16 retcode = SQL_EXEC_GetDatabaseUserName_Internal(userID, userName, maxLen, &actualLen); if (retcode < 0) { if (actualLen > 0) result = FEBUFTOOSMALL; else result = FENOTFOUND; } if (retcode != 0) SQL_EXEC_ClearDiagnostics(NULL); // On success, CLI does not return the length of the string in // actualLen. This function however is supposed to return a value in // actualLen even when the mapping is successful. The value returned // should not account for a null terminator. if (result == FEOK) actualLen = strlen(userName); return result; }
Lng32 executeUsingLong(Lng32 i) { if (!initialized_) { return -9999; } Lng32 result = 0; if (!result) result = SQL_EXEC_ClearDiagnostics(NULL); if (!result) result = SQL_EXEC_SetDescItem(&inDesc_, 1, SQLDESC_TYPE, SQLTYPECODE_INTEGER, 0); if (!result) result = SQL_EXEC_SetDescItem(&inDesc_, 1, SQLDESC_LENGTH, sizeof(i), 0); if (!result) result = SQL_EXEC_SetDescItem(&inDesc_, 1, SQLDESC_VAR_PTR, (Long) &i, 0); if (!result) result = SQL_EXEC_ExecClose(&stmtId_, &inDesc_, 0); SQL_ERROR_HANDLER(result); return result; }
// This method is called when a message from the master executor // arrives informing the compiler to establish a new user // identity. The return value is a SQLCODE. When a value other than // zero is returned, error information is found in CmpCommon::diags(). // // The method performs the following steps // 1. The method is a no-op if the new user ID is the same as the // current user ID // 2. Call CLI with the new integer user ID and username. This establishes // the new user identity. // 3. Call a helper method that will retrieve the current user ID and // user name from CLI and store copies of those values in data // members. Lng32 CmpSqlSession::setDatabaseUser(Int32 userID, const char *userName) { NABoolean doDebug = FALSE; #if defined(NA_DEBUG_C_RUNTIME) doDebug = (getenv("DBUSER_DEBUG") ? TRUE : FALSE); if (doDebug) { printf("[DBUSER:%d] BEGIN CmpSqlSession::setDatabaseUser\n", (int) getpid()); printf("[DBUSER:%d] Current user ID %d, new user ID %d\n", (int) getpid(), (int) databaseUserID_, (int) userID); } #endif // 1. The method is a no-op if the new user ID is the same as the // current user ID. This assumes that if the user ID match so // do the usernames. Int32 currentUserAsInt = (Int32) databaseUserID_; if (currentUserAsInt == userID) { if (doDebug) printf("[DBUSER:%d] END CmpSqlSession::setDatabaseUser\n", (int) getpid()); return 0; } Lng32 sqlcode = 0; // 2. Call CLI with the new integer user identity sqlcode = SQL_EXEC_SetSessionAttr_Internal(SESSION_DATABASE_USER, userID, (char *)userName); if (sqlcode != 0) { SQL_EXEC_MergeDiagnostics_Internal(*CmpCommon::diags()); SQL_EXEC_ClearDiagnostics(NULL); } if (doDebug) printf("[DBUSER:%d] SQL_EXEC_SetSessionAttr returned %d\n", (int) getpid(), (int) sqlcode); // 3. Call a helper method that will retrieve the current user ID and // user name from CLI and store copies if (sqlcode >= 0) sqlcode = getUserInfoFromCLI(); if (doDebug) printf("[DBUSER:%d] END CmpSqlSession::setDatabaseUserID\n", (int) getpid()); return sqlcode; }
~MXStatement() { if (initialized_) { SQL_EXEC_ClearDiagnostics(NULL); SQL_EXEC_DeallocDesc(&outDesc_); SQL_EXEC_DeallocDesc(&inDesc_); SQL_EXEC_DeallocDesc(&stmtTextDesc_); SQL_EXEC_DeallocStmt(&stmtId_); } delete [] stmtText_; }
// ---------------------------------------------------------------------------- // method: getAuthIDFromAuthName // // Reads the AUTHS table to get the authID associated with the passed // in authorization name // // Returns: FEOK -- found // FENOTFOUND -- auth name not defined // other -- unexpected error // ---------------------------------------------------------------------------- Int16 ComUser::getAuthIDFromAuthName(const char *authName, Int32 &authID) { Int16 result = FEOK; Int16 retcode = SQL_EXEC_GetAuthID(authName,authID); if (retcode < 0) result = FENOTFOUND; if (retcode != 0) SQL_EXEC_ClearDiagnostics(NULL); return result; }
// ---------------------------------------------------------------------------- // method: getUserIDFromUserName // // Reads the AUTHS table to get the userID associated with the passed // in user name // // Returns: FEOK -- found // FENOTFOUND -- user not defined // other -- unexpected error // ---------------------------------------------------------------------------- Int16 ComUser::getUserIDFromUserName(const char *userName, Int32 &userID) { Int16 result = FEOK; Int16 retcode = SQL_EXEC_GetDatabaseUserID_Internal((char *) userName, &userID); if (retcode < 0) result = FENOTFOUND; if (retcode != 0) SQL_EXEC_ClearDiagnostics(NULL); return result; }
// ---------------------------------------------------------------------------- // method: getSessionUser // // Returns sessionUser from the Cli context // ---------------------------------------------------------------------------- Int32 ComUser::getSessionUser(void) { Int32 dbUserID = 0; Int32 rc = 0; SQL_EXEC_ClearDiagnostics(NULL); rc = SQL_EXEC_GetSessionAttr(SESSION_DATABASE_USER_ID, &dbUserID, NULL, 0, NULL); assert(rc >= 0); assert(dbUserID >= SUPER_USER); return dbUserID; }
Lng32 execute() { if (!initialized_) { return -9999; } Lng32 result = 0; if (!result) result = SQL_EXEC_ClearDiagnostics(NULL); if (!result) result = SQL_EXEC_ExecClose(&stmtId_, NULL, 0); SQL_ERROR_HANDLER(result); return result; }
// Retrieve the database user name from CLI. This will be the // USER_NAME column from a USERS row not the EXTERNAL_USER_NAME // column. Int32 SqlciEnv::getDatabaseUserName(NAString &username) { HandleCLIErrorInit(); char buf[1024] = ""; Int32 rc = SQL_EXEC_GetSessionAttr(SESSION_DATABASE_USER_NAME, NULL, buf, 1024, NULL); HandleCLIError(rc, this); if (rc >= 0) username = buf; if (rc != 0) SQL_EXEC_ClearDiagnostics(NULL); return rc; }
// ---------------------------------------------------------------------------- // method: getCurrentUsername // // Returns size of username // ---------------------------------------------------------------------------- bool ComUser::getCurrentUsername( char * username, Int32 maxUsernameLength) { SQL_EXEC_ClearDiagnostics(NULL); Int32 usernameLength = 0; Int32 rc = SQL_EXEC_GetSessionAttr(SESSION_DATABASE_USER_ID,NULL, username,maxUsernameLength,&usernameLength); assert(rc >= 0); if (usernameLength > maxUsernameLength) return false; return true; }
void SqlciRWInterfaceExecutor::Close(SqlciEnv *sqlci_env) { if (prepStmt_) SQL_EXEC_CloseStmt(prepStmt_->getStmt()); SQL_EXEC_ClearDiagnostics(NULL); // Deallocate, if selectCmd. This call also // deallocates the passed prepStmt_. if ((selectCmd_) &&(prepStmt_)) { SqlCmd::deallocate(sqlci_env, prepStmt_); prepStmt_ = NULL; // make sure that this is reset so we dont deallocate // it again in interrupt handler if the break key is hit. global_sqlci_env->resetDeallocateStmt(); } cursorOpened_ = FALSE; }
// ---------------------------------------------------------------------------- // method: getAuthNameFromAuthID // // Maps an integer authentication ID to a name. If the number cannot be // mapped to a name, the numeric ID is converted to a string. // // <authID> Int32 In // is the numeric ID to be mapped to a name. // // <authName> char * In // passes back the name that the numeric ID mapped to. If the ID does // not map to a name, the ASCII equivalent of the ID is passed back. // // <maxLen> Int32 In // is the size of <authName>. // // <actualLen> Int32 & Out // is the size of the auth name in the table. If larger than <maxLen>, // caller needs to supply a larger buffer. // // Returns: Int16 // // FEOK -- Found. User name written to userName. Length // returned in actualLen. // FENOTFOUND -- Not found // FEBUFTOOSMALL -- Found but output buffer is too small. Required // length returned in actualLen. // Other -- Unexpected error // ---------------------------------------------------------------------------- Int16 ComUser::getAuthNameFromAuthID(Int32 authID, char * authName, Int32 maxLen, Int32 & actualLen) { actualLen = 0; int retcode = SQL_EXEC_GetAuthName_Internal(authID,authName,maxLen,actualLen); if (retcode < 0) // ERROR == -1 { if (actualLen > 0) return FEBUFTOOSMALL; return FENOTFOUND; //Should not happen } if (retcode != 0) SQL_EXEC_ClearDiagnostics(NULL); return FEOK; }
// LCOV_EXCL_START Lng32 prepare(const char *stmtText) { if (!initialized_) { return -9999; } delete [] stmtText_; stmtText_ = new char[strlen(stmtText) + 1]; strcpy(stmtText_, stmtText); Lng32 result = 0; if (!result) result = SQL_EXEC_ClearDiagnostics(NULL); if (!result) result = SQL_EXEC_SetDescItem(&stmtTextDesc_, 1, SQLDESC_TYPE, SQLTYPECODE_CHAR, 0); if (!result) result = SQL_EXEC_SetDescItem(&stmtTextDesc_, 1, SQLDESC_LENGTH, strlen(stmtText_), 0); if (!result) result = SQL_EXEC_SetDescItem(&stmtTextDesc_, 1, SQLDESC_VAR_PTR, (Long) stmtText_, 0); if (!result) result = SQL_EXEC_Prepare(&stmtId_, &stmtTextDesc_); if (!result) result = SQL_EXEC_DescribeStmt(&stmtId_, &inDesc_, &outDesc_); if (!result) result = SQL_EXEC_GetDescEntryCountBasic(&outDesc_, &numOutColumns_); if (!result) result = SQL_EXEC_GetDescEntryCountBasic(&inDesc_, &numInColumns_); SQL_ERROR_HANDLER(result); return result; }
void ExExeUtilTcb::restoreMaintainControlTableTimeout(char * catalog) { Lng32 cliRC; char buf[400+ComMAX_1_PART_EXTERNAL_UTF8_NAME_LEN_IN_BYTES]; Lng32 markValue = -1; // If the restoration timeout flag is not set, // then just return. if (!restoreTimeout_) return; markValue = getDiagsArea()->mark(); // Reset the timeout to its previous setting. // Errors are ignored. strcpy(buf, "SET TABLE "); strcat(buf, catalog); strcat(buf, ".\"@MAINTAIN_SCHEMA@\".\"@MAINTAIN_CONTROL_INFO@\" "); strcat(buf, " TIMEOUT RESET;"); cliRC = cliInterface()->executeImmediate(buf); if (cliRC < 0) { // ignore any error occurring from the executeImmediate call // rewind to not report this one error getDiagsArea()->rewind(markValue); SQL_EXEC_ClearDiagnostics(NULL); return; } restoreTimeout_ = FALSE; return; }
// If a user name was specified on the command line, call CLI to set // the database user identity. void SqlciEnv::setUserIdentityInCLI() { if (userNameFromCommandLine_.length() > 0) { // Within this function we do not want CLI errors to be // fatal. Setting specialError_ to 0 ensures they are not. We also // save the current value of specialError_ and restore if after // the CLI calls. Lng32 previousSpecialError = specialError_; specialError_ = 0; HandleCLIErrorInit(); Lng32 sqlcode = SQL_EXEC_SetSessionAttr_Internal(SESSION_DATABASE_USER_NAME, 0, (char *) userNameFromCommandLine_.data()); HandleCLIError(sqlcode, this); if (sqlcode >= 0) printf("\nDatabase user: %s\n\n", userNameFromCommandLine_.data()); if (sqlcode != 0) SQL_EXEC_ClearDiagnostics(NULL); specialError_ = previousSpecialError; } else { // Call CLI to retrieve the current user identity. This is only // done to see if CLI generates errors or warnings that we should // display. For example, CLI was not able to establish a default // user identity, perhaps metadata is corrupt, we should display // that information. Int32 uid = 0; getDatabaseUserID(uid); } }
void ExExeUtilTcb::setMaintainControlTableTimeout(char * catalog) { Lng32 cliRC; char buf[400+ComMAX_1_PART_EXTERNAL_UTF8_NAME_LEN_IN_BYTES]; Lng32 markValue = -1; char timeoutHoldBuf[100]; Lng32 timeoutHoldBufLen = 0; // The MAINTAIN_CONTROL_TABLE_TIMEOUT CQD default is '30000', 5 minutes restoreTimeout_ = FALSE; strcpy(buf, "showcontrol default "); strcat(buf, "MAINTAIN_CONTROL_TABLE_TIMEOUT"); strcat(buf, " , match full, no header;"); markValue = getDiagsArea()->mark(); // get the current value of MAINTAIN_CONTROL_TABLE_TIMEOUT cliRC = cliInterface()-> executeImmediate(buf, timeoutHoldBuf, &timeoutHoldBufLen); // If we were unable to obtain the default value, // then just return and allow the 60 second general // timeout for a table to remain. if (cliRC < 0) { // Ignore any error occurring from the executeImmediate call. // Rewind to not report this one error. getDiagsArea()->rewind(markValue); SQL_EXEC_ClearDiagnostics(NULL); return; } // The timeout setting will be retained for the duration // of executing the maintain tasks. // Execute the set table timeout statement. // The SET TABLE TIMEOUT statement sets a dynamic timeout value for a lock timeout // or a stream timeout in the environment of the current session. The dynamic timeout // value overrides the compiled static timeout value in the execution of subsequent DML // statements. markValue = getDiagsArea()->mark(); strcpy(buf, "SET TABLE "); strcat(buf, catalog); strcat(buf, ".\"@MAINTAIN_SCHEMA@\".\"@MAINTAIN_CONTROL_INFO@\" "); strcat(buf, " TIMEOUT "); strcat(buf, " '"); strcat(buf, timeoutHoldBuf); strcat(buf, "';"); cliRC = cliInterface()->executeImmediate(buf); if (cliRC < 0) { // Ignore any error occurring from the executeImmediate call. // Rewind to not report this one error. getDiagsArea()->rewind(markValue); SQL_EXEC_ClearDiagnostics(NULL); return; } // Set the flag to indicate the timeout // should be restored restoreTimeout_ = TRUE; return; }
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; }
// Private method to retrieve user information from CLI and store a // copy in the databaseUserID_ and databaseUserName_ members. The // return value is a SQLCODE. When a value other than zero is // returned, error information is written into CmpCommon::diags(). Lng32 CmpSqlSession::getUserInfoFromCLI() { NABoolean doDebug = FALSE; #if defined (NA_DEBUG_C_RUNTIME) doDebug = (getenv("DBUSER_DEBUG") ? TRUE : FALSE); if (doDebug) printf("[DBUSER:%d] BEGIN CmpSqlSession::getUserInfoFromCLI\n", (int) getpid()); #endif Lng32 sqlcode = 0; Int32 localUserID = 0; char localUserName[MAX_DBUSERNAME_LEN+1] = ""; sqlcode = SQL_EXEC_GetSessionAttr(SESSION_DATABASE_USER_ID, &localUserID, NULL, 0, NULL); if (sqlcode != 0) { SQL_EXEC_MergeDiagnostics_Internal(*CmpCommon::diags()); SQL_EXEC_ClearDiagnostics(NULL); } if (doDebug) printf("[DBUSER:%d] SQL_EXEC_GetSessionAttr returned %d\n", (int) getpid(), (int) sqlcode); if (sqlcode >= 0) { sqlcode = SQL_EXEC_GetSessionAttr(SESSION_DATABASE_USER_NAME, NULL, localUserName, sizeof(localUserName), NULL); if (sqlcode != 0) { SQL_EXEC_MergeDiagnostics_Internal(*CmpCommon::diags()); SQL_EXEC_ClearDiagnostics(NULL); } if (doDebug) printf("[DBUSER:%d] SQL_EXEC_GetSessionAttr returned %d\n", (int) getpid(), (int) sqlcode); } if (sqlcode >= 0) { databaseUserID_ = localUserID; databaseUserName_ = localUserName; // On Linux the value of externalUserName_ is always the same as // databaseUserName_ externalUserName_ = localUserName; if (doDebug) printf("[DBUSER:%d] Retrieved user ID %d, name [%s]\n", (int) getpid(), (int) localUserID, localUserName); } if (doDebug) printf("[DBUSER:%d] END CmpSqlSession::getUserInfoFromCLI\n", (int) getpid()); return sqlcode; }
Int32 arkcmp_main_entry() { if (getenv("SQL_CMP_MSGBOX_PROCESS") != NULL ) MessageBox(NULL, "Server: Process Launched", "tdm_arkcmp", MB_OK|MB_ICONINFORMATION); // The following call causes output messages to be displayed in the // same order on NSK and Windows. cout.sync_with_stdio(); initializeArkcmp(); try { { // a local ctor scope, within a try block // Set up the context info for the connection, it contains the variables // persistent through each statement loops. CmpContext *context=NULL; NAHeap *parentHeap = GetCliGlobals()->getCurrContextHeap(); NAHeap *cmpContextHeap = new (parentHeap) NAHeap((char *)"Cmp Context Heap", parentHeap, (Lng32)524288); try { CLISemaphore *cliSemaphore; cliSemaphore = GetCliGlobals()->getSemaphore(); cliSemaphore->get(); context= new (cmpContextHeap)CmpContext(CmpContext::IS_DYNAMIC_SQL, cmpContextHeap); cliSemaphore->release(); } catch (...) { ArkcmpErrorMessageBox (ARKCMP_ERROR_PREFIX "- Cannot initialize Compiler global data.", ERROR_SEV, FALSE, FALSE, TRUE); return(1); } // moved down the IdentifyMyself so that it can be determined that the // context has not yet been set up IdentifyMyself::SetMyName(I_AM_EMBEDDED_SQL_COMPILER); context->setIsEmbeddedArkcmp(TRUE); context->initContextGlobals(); context->envs()->cleanup(); // Clear the CLI globals context area if there are any leftover CLI diags //This is a fresh context and shouldn't have CLI diags. SQL_EXEC_ClearDiagnostics(NULL); assert(cmpCurrentContext == context); // Clear the SQL text buffer in the event logging area. cmpCurrentContext->resetLogmxEventSqlText(); } } catch(BaseException& bE) { char msg[500]; sprintf(msg, "%s BaseException: %s %d", ARKCMP_ERROR_PREFIX, bE.getFileName(), bE.getLineNum()); ArkcmpFatalError(msg); } catch(...) { ArkcmpFatalError(ARKCMP_ERROR_PREFIX "Fatal exception."); } return 0; }
short ExExeUtilLongRunningTcb::doLongRunning() { Lng32 cliRC =0; short retcode = 0; NABoolean xnAlreadyStarted = FALSE; // Get the globals stucture of the master executor. ExExeStmtGlobals *exeGlob = getGlobals()->castToExExeStmtGlobals(); ExMasterStmtGlobals *masterGlob = exeGlob->castToExMasterStmtGlobals(); ex_queue_entry * pentry_down = qparent_.down->getHeadEntry(); ExExeUtilPrivateState & pstate = *((ExExeUtilPrivateState*) pentry_down->pstate); CliGlobals *cliGlobals = 0; cliGlobals = GetCliGlobals(); ex_assert(cliGlobals != NULL, "Cli globals is NULL - should have been allocated already"); if (cliGlobals->isESPProcess()) { if (!currTransaction_) currTransaction_ = new (getHeap()) ExTransaction (cliGlobals, getHeap()); } else // in master executor { currTransaction_ = masterGlob->getStatement()->getContext()->getTransaction(); } if (currTransaction_->xnInProgress()) { xnAlreadyStarted = TRUE; } // cannot run LRU when a user transaction is in progress if (xnAlreadyStarted) { ExHandleErrors(qparent_, pentry_down, 0, getGlobals(), NULL, (ExeErrorCode)(-8603), NULL, exeUtilTdb().getTableName() ); return (-8603); } SQL_EXEC_ClearDiagnostics(NULL); // no Xn in progress. Start one. cliRC = currTransaction_->beginTransaction (); if (cliRC < 0) { ExHandleErrors(qparent_, pentry_down, 0, getGlobals(), NULL, (ExeErrorCode)(cliRC), NULL, exeUtilTdb().getTableName() ); return (short) cliRC; } retcode = executeLongRunningQuery(); // Rollback the transaction, if there is an error. if (retcode < 0) { // rollback the transaction cliRC = currTransaction_->rollbackTransaction (); return retcode; } else { // commit the transaction cliRC = currTransaction_->commitTransaction (); if (cliRC < 0) { ExHandleErrors(qparent_, pentry_down, 0, getGlobals(), NULL, (ExeErrorCode)(cliRC), NULL, exeUtilTdb().getTableName() ); return short(cliRC); } addTransactionCount(); } return retcode; }
// LCOV_EXCL_START Lng32 init(const char *&status) { Lng32 result = 0; status = "OK"; if (initialized_) return result; stmtText_ = NULL; if (result == 0) { result = SQL_EXEC_ClearDiagnostics(NULL); if (result != 0) { status = "SQL_EXEC_ClearDiagnostics failed"; } } if (result == 0) { result = SQL_EXEC_AllocStmt(&stmtId_, 0); if (result != 0) { status = "SQL_EXEC_AllocStmt failed"; } } if (result == 0) { result = SQL_EXEC_AllocDesc(&stmtTextDesc_, 1); if (result != 0) { status = "SQL_EXEC_AllocDesc failed for statement text"; SQL_EXEC_DeallocStmt(&stmtId_); } } if (result == 0) { result = SQL_EXEC_AllocDesc(&inDesc_, MAX_COLUMNS_IN_DESC); SQL_ERROR_HANDLER(result); if (result != 0) { status = "SQL_EXEC_AllocDesc failed for input descriptor"; SQL_EXEC_DeallocDesc(&stmtTextDesc_); SQL_EXEC_DeallocStmt(&stmtId_); } } if (result == 0) { result = SQL_EXEC_AllocDesc(&outDesc_, MAX_COLUMNS_IN_DESC); SQL_ERROR_HANDLER(result); if (result != 0) { status = "SQL_EXEC_AllocDesc failed for output descriptor"; SQL_EXEC_DeallocDesc(&inDesc_); SQL_EXEC_DeallocDesc(&stmtTextDesc_); SQL_EXEC_DeallocStmt(&stmtId_); } } if (result == 0) initialized_ = true; SQL_ERROR_HANDLER(result); return result; }