Exemple #1
0
 protected internal virtual void SaveCommandObject(out ArrayList sysParameters, out int sysParameterCount, out string sysCommandText)
 {
     System.Data.IDbCommand underlyingCommand = this.UnderlyingCommand;
     sysParameterCount = ((underlyingCommand.Parameters != null) ? underlyingCommand.Parameters.Count : 0);
     sysCommandText    = string.Copy(underlyingCommand.CommandText);
     if (sysParameterCount == 0)
     {
         sysParameters = null;
     }
     else
     {
         sysParameters = new ArrayList(sysParameterCount);
         ParameterCollectionWrapper.Enumerator enumerator = this.m_parameterCollection.GetEnumerator();
         while (enumerator.MoveNext())
         {
             ParameterWrapper current = enumerator.Current;
             sysParameters.Add(current);
         }
     }
 }
Exemple #2
0
        protected internal virtual bool RewriteMultiValueParameters(int sysParameterCount, ServerType serverType)
        {
            if (0 >= sysParameterCount)
            {
                return(false);
            }
            bool result = false;

            System.Data.IDbCommand underlyingCommand = this.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 = this.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 = CommandWrapper.GenerateStringFromMultiValue(parameterMultiValueWrapper, flag, serverType);
                    if (flag)
                    {
                        current.Value = value;
                    }
                    else
                    {
                        string          str2            = "(?<ParameterName>" + Regex.Escape(parameterMultiValueWrapper.ParameterName) + ")";
                        Regex           regex           = new Regex(text + str2 + text, options);
                        MatchCollection matchCollection = regex.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);
        }