protected internal virtual void SaveCommandObject(out ArrayList sysParameters, out int sysParameterCount, out string sysCommandText) { System.Data.IDbCommand underlyingCommand = UnderlyingCommand; sysParameterCount = ((underlyingCommand.Parameters != null) ? underlyingCommand.Parameters.Count : 0); sysCommandText = string.Copy(underlyingCommand.CommandText); if (sysParameterCount == 0) { sysParameters = null; return; } sysParameters = new ArrayList(sysParameterCount); ParameterCollectionWrapper.Enumerator enumerator = m_parameterCollection.GetEnumerator(); while (enumerator.MoveNext()) { ParameterWrapper current = enumerator.Current; sysParameters.Add(current); } }
protected internal virtual bool RewriteMultiValueParameters(int sysParameterCount, ServerType serverType) { if (0 >= sysParameterCount) { return(false); } bool result = false; System.Data.IDbCommand underlyingCommand = UnderlyingCommand; StringBuilder stringBuilder = null; RegexOptions options = RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture | RegexOptions.Compiled | RegexOptions.Singleline; string str = Regex.Escape("-+()#,:&*/\\^<=>"); string text = "([" + str + "\\s])"; bool flag = System.Data.CommandType.StoredProcedure == underlyingCommand.CommandType; if (!flag) { stringBuilder = new StringBuilder(underlyingCommand.CommandText); } int num = 0; ParameterCollectionWrapper.Enumerator enumerator = m_parameterCollection.GetEnumerator(); while (enumerator.MoveNext()) { ParameterWrapper current = enumerator.Current; ParameterMultiValueWrapper parameterMultiValueWrapper = current as ParameterMultiValueWrapper; if (parameterMultiValueWrapper != null && parameterMultiValueWrapper.Values != null) { result = true; string value = GenerateStringFromMultiValue(parameterMultiValueWrapper, flag, serverType); if (flag) { current.Value = value; continue; } string str2 = "(?<ParameterName>" + Regex.Escape(parameterMultiValueWrapper.ParameterName) + ")"; MatchCollection matchCollection = new Regex(text + str2 + text, options).Matches(stringBuilder.ToString()); if (matchCollection.Count > 0) { if (StringComparer.InvariantCultureIgnoreCase.Compare(parameterMultiValueWrapper.ParameterName, "?") == 0) { if (num < matchCollection.Count) { string text2 = matchCollection[num].Result("${ParameterName}"); if (text2 != null && 1 == text2.Length) { stringBuilder.Remove(matchCollection[num].Index + 1, text2.Length); stringBuilder.Insert(matchCollection[num].Index + 1, value); } } } else { for (int num2 = matchCollection.Count - 1; num2 >= 0; num2--) { string text3 = matchCollection[num2].Result("${ParameterName}"); if (text3 != null && 1 < text3.Length) { RSTrace.DataExtensionTracer.Assert(text3.Length == parameterMultiValueWrapper.ParameterName.Length); stringBuilder.Remove(matchCollection[num2].Index + 1, text3.Length); stringBuilder.Insert(matchCollection[num2].Index + 1, value); } } } } if (RSTrace.DataExtensionTracer.TraceVerbose) { RSTrace.DataExtensionTracer.Trace(TraceLevel.Verbose, "Query rewrite (removed parameter): " + parameterMultiValueWrapper.ParameterName.MarkAsModelInfo()); } underlyingCommand.Parameters.Remove(parameterMultiValueWrapper.UnderlyingParameter); } else if (parameterMultiValueWrapper != null && parameterMultiValueWrapper.Values == null && StringComparer.InvariantCultureIgnoreCase.Compare(parameterMultiValueWrapper.ParameterName, "?") == 0) { num++; } } if (!flag) { if (RSTrace.DataExtensionTracer.TraceVerbose) { RSTrace.DataExtensionTracer.Trace(TraceLevel.Verbose, "Query rewrite (original query): " + underlyingCommand.CommandText.MarkAsPrivate()); RSTrace.DataExtensionTracer.Trace(TraceLevel.Verbose, "Query rewrite (rewritten query): " + stringBuilder.ToString().MarkAsPrivate()); } underlyingCommand.CommandText = stringBuilder.ToString(); } return(result); }