Esempio n. 1
0
        /// <summary>
        /// 新加参数
        /// </summary>
        /// <param name="parameter"></param>
        public void Add(ParameterPosition parameter)
        {
            if (this.parameterPositions == null)
            {
                this.parameterPositions = new List <ParameterPosition>();
                this.parameterPositions.Add(parameter);
                this.parameterPositionCount++;
                return;
            }

            this.parameterPositions.Add(parameter);
            this.parameterPositionCount++;
        }
Esempio n. 2
0
        /// <summary>
        /// 在参数里面查询第一个匹配开始位置(以前一个位置为终点,用于获取参数的前缀去确定是文本参数还是标准参数)的参数
        /// </summary>
        /// <param name="parameters"></param>
        /// <param name="start"></param>
        /// <returns></returns>
        protected virtual ParameterPosition MathPosition(List <ParameterPosition> parameters, int start)
        {
            if (parameters.Count == 0)
            {
                return(null);
            }

            ParameterPosition found = null;

            for (var i = 0; i < parameters.Count; i++)
            {
                if (parameters[i].PrefixStart == start)
                {
                    found = parameters[i];
                    parameters.Remove(found);
                    return(found);
                }
            }

            return(null);
        }
Esempio n. 3
0
 public override bool IfTextParameter(ParameterPosition parameterPosition)
 {
     return(true);
 }
Esempio n. 4
0
 /// <summary>
 /// 是否格式化参数
 /// </summary>
 /// <param name="parameterPosition"></param>
 /// <returns></returns>
 public virtual bool IfTextParameter(ParameterPosition parameterPosition)
 {
     return(parameterPosition.TextParameter);
 }
Esempio n. 5
0
        internal TextLabel ReadTextNodeUsingFormatLine(string text, ThunderWriter writer, SequenceStringReader readerHelper, string parameterPrefix)
        {
            var i      = -1;
            var length = text.Length;
            var label  = new TextLabel()
            {
            };
            var  hack  = 0;
            var  cuted = false;
            char last  = 'a';

            while (true)
            {
                i++;
                if (i >= length)
                {
                    break;
                }

                if (readerHelper.IsWhiteSpaceChangeLine(text[i]))
                {
                    hack++;
                    continue;
                }

                i--;
                break;
            }

            while (true)
            {
                i++;
                if (i >= length)
                {
                    break;
                }

                switch (text[i])
                {
                case '\u0020':
                case '\u0009':
                {
                    if (readerHelper.IsWhiteSpaceChangeLine(last))
                    {
                        hack++;
                    }
                    else
                    {
                        writer.Write(last = text[i]);
                    }
                }
                break;

                case '\u000A':
                case '\u000D':
                {
                    switch (last)
                    {
                    case '\u0020':
                    case '\u0009':
                    {
                        writer.Write(last = text[i]);
                    }
                    break;

                    case '\u000A':
                    case '\u000D':
                    {
                        hack++;
                    }
                    break;

                    default:
                    {
                        writer.Write(last = text[i]);
                    }
                    break;
                    }
                }
                break;

                case '\'':
                {
                    writer.Write(last = text[i]);
                    var start = i;
                    var end   = text.Length;
                    while (true)
                    {
                        start++;
                        if (text.Length <= start)
                        {
                            throw new DataFormatException("sql tag {0} can not find ' char;", this.Id);
                        }

                        if (text[start] == '$')
                        {
                            last = '$';
                            writer.Write('$');
                            var start2 = start;
                            var end2   = text.Length;
                            while (true)
                            {
                                start2++;
                                if (text.Length <= start2)
                                {
                                    break;
                                }

                                if (text[start2] == '\'')
                                {
                                    throw new DataFormatException("sql tag {0} can not find $ char;", this.Id);
                                }

                                if (text[start2] == '$')
                                {
                                    writer.Write(last = '$');
                                    end2  = start2 - 1;
                                    cuted = true;
                                    break;
                                }

                                writer.Write(last = text[start2]);
                                if (this.Pause(readerHelper, text[start2]))
                                {
                                    end2 = start2 - 1;
                                    break;
                                }
                            }

                            //从引号到$中间多了某些字符
                            var ss        = start + 1;
                            var se        = end2 - start;
                            var name      = text.Sub(ss, se);
                            var parameter = new ParameterPosition()
                            {
                                Name           = name,
                                SourcePrefix   = new string(text[start], 1),
                                ActualPrefix   = parameterPrefix,
                                StartPosition  = start + 1 - hack,
                                PrefixStart    = start - hack,
                                StopPosition   = end2 - hack,
                                PositionLength = end2 - start,
                            };

                            if (cuted)
                            {
                                parameter.StopPosition   += 1;
                                parameter.PositionLength += 1;
                                cuted = false;
                            }

                            parameter.TextParameter = parameter.SourcePrefix == "$";
                            label.Add(parameter);
                            start = start2;
                        }
                        else if (text[start] == '@')
                        {
                            throw new DataFormatException("sql tag {0} reading '@' is error;", this.Id);
                        }
                        else
                        {
                            writer.Write(last = text[start]);
                        }

                        if (text[start] == '\'')
                        {
                            i = start;
                            break;
                        }
                    }
                }
                break;

                case '$':
                {
                    last = '$';
                    writer.Write('$');
                    var start = i;
                    var end   = text.Length;
                    while (true)
                    {
                        start++;
                        if (text.Length <= start)
                        {
                            throw new ArgumentOutOfRangeException($"start with $ must end with $,position is {start}");
                        }

                        if (text[start] == '$')
                        {
                            last = '$';
                            writer.Write('$');
                            end   = start - 1;
                            cuted = true;
                            break;
                        }

                        writer.Write(last = text[start]);
                        if (this.Pause(readerHelper, text[start]))
                        {
                            end = start - 1;
                            break;
                        }
                    }

                    var name      = text.Sub(i + 1, end - i);
                    var parameter = new ParameterPosition()
                    {
                        Name           = name,
                        SourcePrefix   = new string(text[i], 1),
                        ActualPrefix   = parameterPrefix,
                        StartPosition  = (i + 1) - hack,
                        PrefixStart    = i - hack,
                        StopPosition   = end - hack,
                        PositionLength = (end - i),
                    };

                    if (cuted)
                    {
                        parameter.StopPosition   += 1;
                        parameter.PositionLength += 1;
                        cuted = false;
                    }

                    parameter.TextParameter = parameter.SourcePrefix == "$";
                    label.Add(parameter);
                    i = start;
                }
                break;

                case '@':
                {
                    last = parameterPrefix.Last();
                    writer.Write(parameterPrefix);
                    var start = i;
                    var end   = text.Length;
                    while (true)
                    {
                        start++;
                        if (text.Length <= start)
                        {
                            end = start - 1;
                            break;
                        }

                        writer.Write(last = text[start]);

                        if (this.Pause(readerHelper, text[start]))
                        {
                            end = start - 1;
                            break;
                        }
                    }

                    var name      = text.Sub(i + 1, end - i);
                    var parameter = new ParameterPosition()
                    {
                        Name           = name,
                        SourcePrefix   = new string(text[i], 1),
                        ActualPrefix   = parameterPrefix,
                        StartPosition  = (i + 1) - hack,
                        PrefixStart    = i - hack,
                        StopPosition   = (i + end - i) - hack,
                        PositionLength = (end - i),
                    };

                    parameter.TextParameter = parameter.SourcePrefix == "$";

                    /*前缀为@@这样的长度*/
                    if (parameterPrefix.Length > 1)
                    {
                        parameter.StopPosition   += parameterPrefix.Length - 1;
                        parameter.PositionLength += parameterPrefix.Length - 1;
                    }

                    label.Add(parameter);
                    i = start;
                }
                break;

                default:
                {
                    writer.Write(last = text[i]);
                }
                break;
                }
            }

            label.SqlText    = writer.ToString();
            this.TextLength += label.SqlText.Length;
            writer.Clear();
            return(label);
        }