示例#1
0
char * ComRtGetIsoMappingName()
{
  Lng32 ime = ComRtGetIsoMappingEnum();

  return (char*)CharInfo::getCharSetName((CharInfo::CharSet)ime);
}
void CRUSQLDynamicStatementContainer::DynamicStmt::PrepareStatement(BOOL DeleteUsedStmt)
{
	if (NULL == sql_)
	{
		return;
	}

	char sqlForCompilation[MAX_SQL_TEXT_SIZE];	
	
	// Prepare the sql text for compilation by inserting all compiled params
	// into the sql text
	PrepareSqlText(sqlForCompilation);

	// We compile the statement in nil transaction state,in such case
	// the compiler starts his own transaction and commits in the end
	// This way the compiler locks are freed as soon as possible
	CUOFsTransManager &transManager = 
		CRUGlobals::GetInstance()->GetTransactionManager();
	// Remember the current txn for later use
	Lng32 transIdx = transManager.GetCurrentTrans();

	transManager.LeaveTransaction();

	// now we can prepare the statement by using DMOL objects;
        CUOSessionInfo sessionInfo(TRUE, FALSE,FALSE);
	CDMConnection *pConnect = inherited::GetConnection();
	pConnect->SetAllowSpecialSyntax(TRUE);
	pConnect->SetAllowServicesOpen(sessionInfo.BelongsToServicesRole());
	prepared_ = TRUE;

	CDMPreparedStatement *pPrepStmt = NULL;

	short retry_delay = 1000 ; // milliseconds.
	for (Int32 retry = 0; retry < 2; retry++)
	{
#pragma nowarn(1506)   // warning elimination 
		retry_delay = retry_delay * (retry + 1);
#pragma warn(1506)  // warning elimination 
		try 
		{
		  // need to add here the handling of compiled params
			/* --------------
			   Date: 1/21/08 
			   Charset: Use internal flag SQLCHARSETCODE_ISO_MAPPING
			   ---------------- */

		   /* --- pPrepStmt = 
				  pConnect->PrepareStatement(
				  sqlForCompilation,
				  NULL, // no statement name
				  // The connection does NOT own the statement
					  CDMConnection::eItemIsOwned
				  );
             --- */
#ifdef NA_NSK 
         Lng32 iso_cs = 0 ;
         SQLCHARSET_CODE mapCS = SQLCHARSETCODE_ISO88591;

		 iso_cs = ComRtGetIsoMappingEnum();
		 if (iso_cs == 1) 
			 mapCS = SQLCHARSETCODE_ISO88591;

		 else if (iso_cs == 10)
			 mapCS = SQLCHARSETCODE_SJIS ;

		 else if (iso_cs == 15)
             mapCS = SQLCHARSETCODE_UTF8 ;
		 else 
		 {    
			 CDSException e;
	         e.SetError(IDS_GET_ISO_MAPPING_FAILED);
			 
			 char precision_str[100];
			 sprintf(precision_str, "REFRESH_SQLCHARSETCODE: global define=%d", iso_cs);
		     e.AddArgument(precision_str);
	         throw e;
		 }
#endif // NA_NSK 

		   pPrepStmt = 
				  pConnect->PrepareStmtWithCharSet(
				  sqlForCompilation,
#ifdef NA_NSK 
				  mapCS,  // CLI Charset enum, defined in sqlcli.h
#else 
				  SQLCHARSETCODE_UTF8,
#endif
				  NULL, // no statement name
				  // The connection does NOT own the statement
					  CDMConnection::eItemIsOwned
				  );

		  break; // no retry needed, exit retry loop

		}
		catch (CDSException &ex)
		{
			// The purpose of this method call is to detect compilation errors 
			// that are originated from a temporary lock on the OBJECTS table 
			// (error 73) and execute retry. Due to the catalog error mechanism 
			// the projected error code is currently 1100.
			if (ex.IsErrorFoundAndRetryNeeded(-1100, retry_delay))
			{
				// error was found try again
				continue;
			}

			if (-1 != transIdx)
			{
				// go back to the previous txn
				transManager.SetCurrentTrans(transIdx);
			}
			
#ifdef _DEBUG
			ex.SetError(IDS_RU_DYNAMIC_COMPILATION_FAILED);
			CDSString sqlString(sqlForCompilation);
			sqlString.TrimRight();
			sqlString.TrimLeft();
			ex.AddArgument(sqlString);
#endif
			throw ex;	// Re-throw
		}
	}

	if (-1 != transIdx)
	{
		// go back to the previous txn
		transManager.SetCurrentTrans(transIdx);
	}

	inherited::SetPreparedStatement(pPrepStmt, DeleteUsedStmt);

}