private void BuildOwaProc() { // build the structure (class instance) that represents the main procedure call OwaProcedure owaProc = new OwaProcedure(); owaProc.CheckForDownload = true; owaProc.BeforeProc = DadConfig.BeforeProcedure; owaProc.AfterProc = DadConfig.AfterProcedure; owaProc.RequestValidationFunction = DadConfig.RequestValidationFunction; owaProc.IsSoapRequest = IsSoapRequest; if (IsFlexibleParams) { // flexible parameter mode (name/value collections) owaProc.MainProc = ProcName; owaProc.MainProcParams = ":b1, :b2"; } else if (IsPathAlias) { // path aliasing (forward URL to PathAlias procedure) owaProc.MainProc = DadConfig.PathAliasProcedure; // no request validation needed/wanted for PathAliasProcedure owaProc.RequestValidationFunction = ""; if (DadConfig.PathAliasIncludeParameters) { // forward querystring and form parameters as well as URL owaProc.MainProcParams = ":b1, :b2, :b3"; } else { // standard mod_plsql behaviour (just forward the URL) owaProc.MainProcParams = ":b1"; } } else if (IsDocumentPath) { // download procedure via DocumentPath folder (no parameters, procedure is expected to identify file using get_cgi_env) // see http://download.oracle.com/docs/cd/B15897_01/web.1012/b14010/concept.htm#i1010535 owaProc.MainProc = DadConfig.DocumentProcedure; } else if (IsXdbAlias) { // XDB resource will be fetched by separate call owaProc.MainProc = "null"; owaProc.CheckForDownload = false; } else { owaProc.MainProc = ProcName; string sqlParams = ""; int paramCount = 0; foreach (NameValuePair nvp in _requestParams) { paramCount = paramCount + 1; sqlParams = StringUtil.AppendStr(sqlParams, nvp.Name + " => :b" + paramCount.ToString(), ", "); if (logger.IsDebugEnabled) { logger.Debug("Parameter " + paramCount.ToString() + ": " + nvp.Name + " = " + nvp.DebugValue); } } if (sqlParams.Length > 0) { owaProc.MainProcParams = sqlParams; } else { owaProc.MainProcParams = ""; } } OwaProc = owaProc; }
public bool ExecuteMainProc(OwaProcedure owaProc, List <NameValuePair> paramList, bool describeProc, string procName) { int[] bindBucketLengths = _dadConfig.BindBucketLengths; int[] bindBucketWidths = _dadConfig.BindBucketWidths; NameValueCollection procParams = new NameValueCollection(); string dataType = ""; bool paramExists = false; string sql = ""; int paramCount = 0; if (describeProc) { procParams = DescribeSingleProc(_dadName, procName); sql = owaProc.BuildSQLStatement(procParams, paramList); } else { sql = owaProc.BuildSQLStatement(); } OracleCommand cmd = new OracleCommand(sql, _conn); OracleParameter pReturnValue = null; OracleParameter pIsDownload = null; if (owaProc.RequestValidationFunction.Length > 0) { OracleParameter pName = cmd.Parameters.Add("p_proc_name", OracleDbType.Varchar2, PLSQL_MAX_STR_SIZE, procName, ParameterDirection.Input); } if (owaProc.IsSoapRequest) { pReturnValue = cmd.Parameters.Add("p_return_value", OracleDbType.Clob, ParameterDirection.Output); } foreach (NameValuePair nvp in paramList) { if (describeProc) { paramExists = (procParams.GetValues(nvp.Name) != null); if (paramExists) { dataType = procParams.GetValues(nvp.Name)[0]; } } else { paramExists = true; dataType = ""; } if (paramExists) { paramCount = paramCount + 1; if (nvp.ValueType == ValueType.ArrayValue || dataType == "PL/SQL TABLE") { OracleParameter p = cmd.Parameters.Add("b" + paramCount.ToString(), OracleDbType.Varchar2, ParameterDirection.Input); p.CollectionType = OracleCollectionType.PLSQLAssociativeArray; p.Value = nvp.ValuesAsArray; //p.Size = nvp.Values.Count(); p.Size = GetNextValidSize(nvp.Values.Count, bindBucketLengths); } else { if (nvp.Value.Length > PLSQL_MAX_STR_SIZE || dataType == "CLOB") { OracleParameter p = cmd.Parameters.Add("b" + paramCount.ToString(), OracleDbType.Clob, nvp.Value.Length, nvp.Value, ParameterDirection.Input); } else { OracleParameter p = cmd.Parameters.Add("b" + paramCount.ToString(), OracleDbType.Varchar2, GetNextValidSize(nvp.Value.Length, bindBucketWidths), nvp.Value, ParameterDirection.Input); } } } else { logger.Warn(string.Format("Mismatch between metadata ({0} parameters) and actual invocation ({1} parameters): Parameter '{2}' was not found in metadata, and was skipped to avoid errors.", procParams.Count, paramList.Count, nvp.Name)); } } if (owaProc.CheckForDownload) { pIsDownload = cmd.Parameters.Add("p_is_download", OracleDbType.Int32, ParameterDirection.Output); } logger.Debug("Executing SQL: " + cmd.CommandText); try { cmd.ExecuteNonQuery(); _lastError = ""; _lastErrorCode = 0; } catch (OracleException e) { if (logger.IsDebugEnabled) { logger.Debug("Command failed: " + e.Message); } _lastError = e.Message; _lastErrorCode = e.Number; return(false); } if (owaProc.CheckForDownload) { int isDownload = (int)(OracleDecimal)pIsDownload.Value; IsDownload = (isDownload != 0); if (logger.IsDebugEnabled && IsDownload) { logger.Debug(" IsDownload = True"); } } if (owaProc.IsSoapRequest) { if (pReturnValue.Status == OracleParameterStatus.NullFetched) { _soapReturnValue = ""; } else { OracleClob tempClob = (OracleClob)pReturnValue.Value; _soapReturnValue = tempClob.Value; } } return(true); }