Example #1
0
        public WColumnReferenceExpression(string tableName, string columnName)
        {
            ColumnType = ColumnType.Regular;

            Identifier tableIdent = tableName != null ? new Identifier {
                Value = tableName
            } : null;
            Identifier columnIdent = columnName != null ? new Identifier {
                Value = columnName
            } : null;

            MultiPartIdentifier = new WMultiPartIdentifier(tableIdent, columnIdent);
        }
Example #2
0
        internal void Add(Identifier identifier)
        {
            if (MultiPartIdentifier == null)
            {
                MultiPartIdentifier = new WMultiPartIdentifier();
            }
            if (MultiPartIdentifier.Identifiers == null)
            {
                MultiPartIdentifier.Identifiers = new List <Identifier>();
            }

            MultiPartIdentifier.Identifiers.Add(identifier);
        }
        public static string WMultipartIdentifier(WMultiPartIdentifier multiIdent)
        {
            var sb = new StringBuilder(128);

            for (var i = 0; i < multiIdent.Identifiers.Count; i++)
            {
                if (i > 0)
                {
                    sb.Append('.');
                }
                sb.Append(multiIdent.Identifiers[i].Value);
            }

            return(sb.ToString());
        }
Example #4
0
 private WMultiPartIdentifier ParseMultiPartIdentifier(MultiPartIdentifier name)
 {
     if (name == null)
         return null;
     var wMultiPartIdentifier = new WMultiPartIdentifier
     {
         FirstTokenIndex = name.FirstTokenIndex,
         LastTokenIndex = name.LastTokenIndex,
         Identifiers = name.Identifiers,
     };
     if (name.Identifiers != null)
     {
         wMultiPartIdentifier.Identifiers = new List<Identifier>();
         foreach (var identifier in name.Identifiers)
         {
             if (GraphViewKeywords._keywords.Contains(identifier.Value))
             {
                 var token = _tokens[identifier.FirstTokenIndex];
                 throw new SyntaxErrorException(token.Line, identifier.Value,
                     "System restricted Name cannot be used");
             }
             wMultiPartIdentifier.Identifiers.Add(identifier);
         }
     }
     return wMultiPartIdentifier;
 }
Example #5
0
 private static bool ParseMultiPartIdentifier(
     IList<TSqlParserToken> tokens,
     ref int nextToken,
     ref WMultiPartIdentifier result,
     ref int farestError)
 {
     var firstToken = nextToken;
     var currentToken = nextToken;
     var identifiers = new List<Identifier>();
     Identifier identifier = null;
     if (!ParseIdentifier(tokens, ref currentToken, ref identifier, ref farestError))
         return false;
     identifiers.Add(identifier);
     while (ReadToken(tokens, ".", ref currentToken, ref farestError))
     {
         ParseIdentifier(tokens, ref currentToken, ref identifier, ref farestError);
         identifiers.Add(identifier);
     }
     result = new WMultiPartIdentifier
     {
         Identifiers = identifiers,
         FirstTokenIndex = firstToken,
         LastTokenIndex = currentToken - 1,
     };
     nextToken = currentToken;
     return true;
 }
Example #6
0
        /// <summary>
        /// Finds all graph modification statements (INSERT NODE, INSERT EDGE, DELETE NOTE, DELETE EDGE), 
        /// records their positions in the script as a list of annotations, and replaces them by INSERT and DELETE,
        /// so that the token list can be parsed by the T-SQL parser.
        /// </summary>
        /// <returns>A list of annotations storing the positions of graph modification statements</returns>
        private List<GraphDataModificationAnnotation> FindReplaceGraphModificationStatements(ref IList<ParseError> errors)
        {
            var ret = new List<GraphDataModificationAnnotation>();
            var currentToken = 0;
            var farestError = 0;
            while (currentToken < _tokens.Count)
            {
                var nextToken = currentToken;
                if (ReadToken(_tokens, "insert", ref nextToken, ref farestError))
                {

                    var pos = nextToken;
                    if (ReadToken(_tokens, "node", ref nextToken, ref farestError))
                    {
                        ret.Add(new InsertNodeAnnotation { Position = pos });
                        _tokens[pos].TokenType = TSqlTokenType.MultilineComment;
                        _tokens[pos].Text = "/*__GRAPHVIEW_INSERT_NODE*/";
                        currentToken = nextToken;
                    }
                    else if (ReadToken(_tokens, "edge", ref nextToken, ref farestError))
                    {
                        var identifiers = new WMultiPartIdentifier();
                        if (!ReadToken(_tokens, "into", ref nextToken, ref farestError) ||
                            !ParseMultiPartIdentifier(_tokens, ref nextToken, ref identifiers, ref farestError))
                        {
                            var error = _tokens[farestError];
                            errors.Add(new ParseError(0, error.Offset, error.Line, error.Column, "Incorrect syntax near edge"));
                            return null;
                        }

                        ret.Add(new InsertEdgeAnnotation
                        {
                            Position = pos,
                            EdgeColumn = identifiers.Identifiers.Last(),
                        });
                        var lastColumnIndex = identifiers.Identifiers.Last().LastTokenIndex;
                        _tokens[pos].TokenType = TSqlTokenType.MultilineComment;
                        _tokens[pos].Text = "/*__GRAPHVIEW_INSERT_EDGE*/";
                        if (identifiers.Identifiers.Count == 1)
                        {

                            _tokens[lastColumnIndex].TokenType = TSqlTokenType.MultilineComment;
                            _tokens[lastColumnIndex].Text = "/*__GRAPHVIEW_INSERT_EDGE*/";
                        }
                        else
                        {
                            var firstColumnIndex =
                                identifiers.Identifiers[identifiers.Identifiers.Count - 2].LastTokenIndex + 1;
                            for (var i = firstColumnIndex; i <= lastColumnIndex; ++i)
                            {
                                _tokens[i].TokenType = TSqlTokenType.MultilineComment;
                                _tokens[i].Text = "/*__GRAPHVIEW_INSERT_EDGE*/";
                            }
                        }
                    }
                    currentToken = nextToken;
                }
                else if (ReadToken(_tokens, "delete", ref nextToken, ref farestError))
                {
                    var pos = nextToken;
                    if (ReadToken(_tokens, "node", ref nextToken, ref farestError))
                    {
                        ret.Add(new DeleteNodeAnnotation
                        {
                            Position = pos,
                        });
                        _tokens[pos].TokenType = TSqlTokenType.MultilineComment;
                        _tokens[pos].Text = "/*__GRAPHVIEW_DELETE_NODE*/";
                        currentToken = nextToken;
                    }
                    else if (ReadToken(_tokens, "edge", ref nextToken, ref farestError))
                    {
                        WMatchPath path = null;
                        if (!ParseMatchPath(_tokens, ref nextToken, ref path, ref farestError))
                        {
                            var error = _tokens[farestError];
                            errors.Add(new ParseError(0, error.Offset, error.Line, error.Column, ""));
                            return null;
                        }
                        else if (path.PathNodeList.Count != 1)
                        {
                            var error = _tokens[nextToken];
                            errors.Add(new ParseError(0, error.Offset, error.Line, error.Column, 
                                "Incorrect Syntax Near edge: 1-Height Pattern should be used in Delete Edge statement"));
                            return null;
                        }
                        ret.Add(new DeleteEdgeAnnotation
                        {
                            Position = currentToken,
                            Path = path
                        });

                        _tokens[currentToken].TokenType = TSqlTokenType.Select;
                        _tokens[currentToken].Text = "SELECT";

                        _tokens[pos].TokenType = TSqlTokenType.Identifier;
                        _tokens[pos].Text = path.PathNodeList[0].Item1.BaseIdentifier.Value;

                        _tokens[pos + 1].TokenType = TSqlTokenType.Comma;
                        _tokens[pos + 1].Text = ",";

                        _tokens[pos + 2].TokenType = TSqlTokenType.Identifier;
                        _tokens[pos + 2].Text = path.Tail.BaseIdentifier.Value;

                        for (var i = path.FirstTokenIndex + 1; i < path.LastTokenIndex; ++i)
                        {
                            _tokens[i].TokenType = TSqlTokenType.MultilineComment;
                            _tokens[i].Text = "/*__GRAPHVIEW_DELETE_EDGE*/";
                        }
                        currentToken = nextToken;
                    }
                }
                currentToken++;
            }
            
            return ret;
        }
Example #7
0
        internal void Add(Identifier identifier)
        {
            if (MultiPartIdentifier == null)
            {
                MultiPartIdentifier = new WMultiPartIdentifier();
            }
            if (MultiPartIdentifier.Identifiers == null)
                MultiPartIdentifier.Identifiers = new List<Identifier>();

            MultiPartIdentifier.Identifiers.Add(identifier);
        }
Example #8
0
 public DMultiPartIdentifier(WMultiPartIdentifier identifier)
 {
     Identifiers = identifier.Identifiers;
 }