private static string ColumnName(SqlNode[] segment, int start, int i)
    {
      if (i >= (start + 2) && segment[start + 1].TextEquals("=") && segment[start] is SqlLiteral)
      {
        var lastNode = segment[start] as SqlLiteral;
        if (lastNode != null && lastNode.Type == SqlType.Identifier)
          return lastNode.Text;
      }
      else
      {
        var lastNode = LastNonCommentNode(segment.Skip(start).Take(i - start)).LastNonCommentNode() as SqlLiteral;
        if (lastNode != null && lastNode.TextEquals("*"))
        {
          var idx = Array.IndexOf(segment, lastNode, start);
          if (idx > start && segment[idx - 1] is SqlName)
          {
            return (segment[idx - 1] as SqlName).FullName + "." + lastNode.Text;
          }
          else
          {
            return lastNode.Text;
          }
        }
        else if (lastNode != null && lastNode.Type == SqlType.Identifier)
        {
          return lastNode.Text;
        }
      }

      return null;
    }
Пример #2
0
        int ISqlGroupNode.IndexOf(SqlNode node)
        {
            var ofType = node as T;

            if (ofType == null)
            {
                return(-1);
            }
            return(_nodes.IndexOf(ofType));
        }
Пример #3
0
        public static bool TextEquals(this SqlNode node, string value)
        {
            var literal = node as SqlLiteral;

            if (literal != null && string.Equals(literal.Text, value, StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }
            return(false);
        }
Пример #4
0
        public override bool Equals(SqlNode obj)
        {
            var literal = obj as SqlLiteral;

            if (literal == null)
            {
                return(false);
            }
            return(base.Equals(obj) && this.Text == literal.Text);
        }
Пример #5
0
        private static SqlNode LastNonCommentNode(this SqlNode node)
        {
            if (node == null)
            {
                return(node);
            }

            var last  = node;
            var group = node as ISqlGroupNode;

            while (group != null)
            {
                last  = group.Items.Where(i => i.Type != SqlType.Comment).Last();
                group = last as ISqlGroupNode;
            }

            if (last.Type == SqlType.Comment)
            {
                return(null);
            }
            return(last);
        }
Пример #6
0
 public override bool Equals(SqlNode obj)
 {
   var literal = obj as SqlLiteral;
   if (literal == null) return false;
   return base.Equals(obj) && this.Text == literal.Text;
 }
Пример #7
0
 public virtual bool Equals(SqlNode obj)
 {
   return this.StartOffset == obj.StartOffset;
 }