Пример #1
0
        private void AddParameter(SpliceParameter ParameterValue)
        {
            if (_Step == SPStep.End)
            {
                throw new InvalidOperationException("正在等待以单引号开始的字符串,此时不允许再拼接其它参数。");
            }

            //替换参数值的特殊字符 *****
            string ReplaceText = ParameterValue.Value.ToString();

            ReplaceText = ReplaceText.Replace("'", "''");
            ReplaceText = ReplaceText.Replace("[", "[[]");

            if (_IsRowFilter)
            {
                ReplaceText = ReplaceText.Replace("%", "[%]");
                ReplaceText = ReplaceText.Replace("*", "[*]");
            }

            //处理结束
            _ResultText.Append(ReplaceText);
            if (_Step == SPStep.Para)
            {
                _Step = SPStep.End;
            }
        }
Пример #2
0
        private void AddSqlText(string s)
        {
            if (string.IsNullOrEmpty(s))
            {
                return;
            }

            if (_autoDiscoverParameters)
            {
                if (_step == SPStep.NotSet)
                {
                    if (s[s.Length - 1] == '\'')                        // 遇到一个单引号结束
                    {
                        _sb.Append(s.Substring(0, s.Length - 1));
                        _step = SPStep.EndWith;
                    }
                    else
                    {
                        object val = TryGetValueFromString(s);
                        if (val == null)
                        {
                            _sb.Append(s);
                        }
                        else
                        {
                            this.AddParameter(val.AsQueryParameter());
                        }
                    }
                }
                else if (_step == SPStep.EndWith)
                {
                    // 此时的s应该是字符串参数,不是SQL语句的一部分
                    // _step 在AddParameter方法中统一修改,防止中途拼接非字符串数据。
                    this.AddParameter(s.AsQueryParameter());
                }
                else
                {
                    if (s[0] != '\'')
                    {
                        throw new ArgumentException("正在等待以单引号开始的字符串,但参数不符合预期格式。");
                    }

                    // 找到单引号的闭合输入。
                    _sb.Append(s.Substring(1));
                    _step = SPStep.NotSet;
                }
            }
            else
            {
                // 不检查单引号结尾的情况,此时认为一定是SQL语句的一部分。
                _sb.Append(s);
            }
        }
Пример #3
0
        private void AddParameter(QueryParameter p)
        {
            if (_autoDiscoverParameters && _step == SPStep.Skip)
            {
                throw new InvalidOperationException("正在等待以单引号开始的字符串,此时不允许再拼接其它参数。");
            }


            string name = "@p" + (_count++).ToString();

            _sb.Append(name);
            _parameters.Add(name, p);


            if (_autoDiscoverParameters && _step == SPStep.EndWith)
            {
                _step = SPStep.Skip;
            }
        }
Пример #4
0
 private void AddSqlText(string sqlText)
 {
     if (!string.IsNullOrEmpty(sqlText))
     {
         if (this.AutoDiscoverParameters)
         {
             if (this.spstep == SPStep.NotSet)
             {
                 if (sqlText[sqlText.Length - 1] == '\'')
                 {
                     this.stringBuilder.Append(sqlText.Substring(0, sqlText.Length - 1));
                     this.spstep = SPStep.EndWith;
                 }
                 else
                 {
                     object obj2 = this.TryGetValueFromString(sqlText);
                     if (obj2 == null)
                     {
                         this.stringBuilder.Append(sqlText);
                     }
                     else
                     {
                         this.AddParameter(obj2.AsQueryParameter());
                     }
                 }
             }
             else if (this.spstep == SPStep.EndWith)
             {
                 this.AddParameter(sqlText.AsQueryParameter());
             }
             else
             {
                 if (sqlText[0] != '\'')
                 {
                     throw new ArgumentException("正在等待以单引号开始的字符串,但参数不符合预期格式。");
                 }
                 this.stringBuilder.Append(sqlText.Substring(1));
                 this.spstep = SPStep.NotSet;
             }
         }
         else
         {
             this.stringBuilder.Append(sqlText);
         }
     }
 }
Пример #5
0
 private void AddParameter(QueryParameter p)
 {
     if (this.AutoDiscoverParameters && (this.spstep == SPStep.Skip))
     {
         throw new InvalidOperationException("正在等待以单引号开始的字符串,此时不允许再拼接其它参数。");
     }
     string str = "p" + this.int_0++.ToString();
     if (this.funcParameterQueryDelegate == this.funcAddPrefix)
     {
         string str2 = this.funcParameterQueryDelegate(str);
         this.stringBuilder.Append(str2);
         this.ParametersDict.Add(new KeyValuePair<string, QueryParameter>(str2, p));
     }
     else
     {
         this.stringBuilder.Append(this.funcParameterQueryDelegate(str));
         this.ParametersDict.Add(new KeyValuePair<string, QueryParameter>(this.funcAddPrefix(str), p));
     }
     if (this.AutoDiscoverParameters && (this.spstep == SPStep.EndWith))
     {
         this.spstep = SPStep.Skip;
     }
 }
Пример #6
0
        private void AddSqlText(string AddText)
        {
            if (_Step == SPStep.New)
            {
                AddText = AddText.TrimEnd();
                if (AddText.IndexOf("'") >= 0)
                {
                    // 遇到一个单引号结束
                    _ResultText.Append(AddText);
                    _Step = SPStep.Para;
                }
                //if (AddText[AddText.Length - 1] == '\'')
                //{
                //    // 遇到一个单引号结束
                //    _ResultText.Append(AddText);
                //    _Step = SPStep.Para;
                //}
                //else if (AddText[AddText.Length - 2] == '\'')
                //{
                //    // 遇到一个单引号结束
                //    _ResultText.Append(AddText);
                //    _Step = SPStep.Para;
                //}
                else
                {
                    _ResultText.Append(AddText);
                }
            }
            else if (_Step == SPStep.Para)
            {
                // 此时的s应该是字符串参数,不是SQL语句的一部分
                // _Step 在AddParameter方法中统一修改,防止中途拼接非字符串数据。
                this.AddParameter(SqlSplice.AsQueryParameter(AddText));
            }
            else if (_Step == SPStep.End)
            {
                AddText = AddText.Trim();

                if (AddText.IndexOf("'") < 0)
                {
                    throw new ArgumentException("正在等待以单引号开始的字符串,但参数不符合预期格式。");
                }

                if (AddText.Substring(AddText.IndexOf("'") + 1).Length == 0)
                {
                    _Step = SPStep.New;
                }
                else
                {
                    _Step = SPStep.Para;
                }

                //if (AddText.Length == 1)
                //{
                //    if (AddText[0] != '\'')
                //    {
                //        throw new ArgumentException("正在等待以单引号开始的字符串,但参数不符合预期格式。");
                //    }
                //    _Step = SPStep.New;
                //}
                //else if (AddText.Length == 2)
                //{
                //    if (AddText[0] != '\'' && AddText[1] != '\'')
                //    {
                //        throw new ArgumentException("正在等待以单引号开始的字符串,但参数不符合预期格式。");
                //    }
                //    _Step = SPStep.New;
                //}
                //else
                //{
                //    if (AddText[0] != '\'' && AddText[1] != '\'')
                //    {
                //        throw new ArgumentException("正在等待以单引号开始的字符串,但参数不符合预期格式。");
                //    }
                //    _Step = SPStep.Para;
                //}

                // 找到单引号的闭合输入。
                _ResultText.Append(AddText);
            }
        }
Пример #7
0
        private void AddSqlText(string s)
        {
            if (string.IsNullOrEmpty(s))
            {
                return;
            }

            if (isAutoDiscoverParameters)
            {
                if (step == SPStep.NotSet)
                {
                    if (s[s.Length - 1] == '\'')
                    {	// 遇到一个单引号结束
                        commandTextContainer.Append(s.Substring(0, s.Length - 1));
                        step = SPStep.EndWith;
                    }
                    else
                    {
                        object val = TryGetValueFromString(s);
                        if (val == null)
                        {
                            commandTextContainer.Append(s);
                        }
                        else
                        {
                            this.AddParameter(CPQueryExtensions.GetQueryParameter(val));
                        }
                    }
                }
                else if (step == SPStep.EndWith)
                {
                    // 此时的s应该是字符串参数,不是SQL语句的一部分
                    // _step 在AddParameter方法中统一修改,防止中途拼接非字符串数据。
                    this.AddParameter(CPQueryExtensions.GetQueryParameter(s));
                }
                else
                {
                    if (s[0] != '\'')
                    {
                        throw new ArgumentException("正在等待以单引号开始的字符串,但参数不符合预期格式。");
                    }

                    // 找到单引号的闭合输入。
                    commandTextContainer.Append(s.Substring(1));
                    step = SPStep.NotSet;
                }
            }
            else
            {
                // 不检查单引号结尾的情况,此时认为一定是SQL语句的一部分。
                commandTextContainer.Append(s);
            }
        }
Пример #8
0
        private void AddParameter(QueryParameter p)
        {
            if (isAutoDiscoverParameters && step == SPStep.Skip)
            {
                throw new InvalidOperationException("正在等待以单引号开始的字符串,此时不允许再拼接其它参数。");
            }

            string name = "@hilandParameter" + (parameterCount++).ToString();
            commandTextContainer.Append(name);
            parameters.Add(name, p);

            if (isAutoDiscoverParameters && step == SPStep.EndWith)
            {
                step = SPStep.Skip;
            }
        }