示例#1
0
        public UpdateStatement ParseUpdateStatement(UpdateStatementContext node)
        {
            UpdateStatement statement = new UpdateStatement();

            SingleUpdateStatementContext   single   = node.singleUpdateStatement();
            MultipleUpdateStatementContext multiple = node.multipleUpdateStatement();

            UpdatedElementContext[] updateItems = null;
            ExpressionContext       condition   = null;

            if (single != null)
            {
                statement.TableNames.Add(this.ParseTableName(single.tableName()));

                updateItems = single.updatedElement();
                condition   = single.expression();
            }
            else if (multiple != null)
            {
                updateItems = multiple.updatedElement();
                condition   = multiple.expression();

                statement.FromItems = new List <FromItem>();

                TableSourcesContext tableSources = multiple.tableSources();

                statement.FromItems = this.ParseTableSources(tableSources);
                statement.TableNames.AddRange(statement.FromItems.Select(item => item.TableName));
            }

            if (updateItems != null)
            {
                statement.SetItems.AddRange(updateItems.Select(item =>
                                                               new NameValueItem()
                {
                    Name = new TokenInfo(item.fullColumnName())
                    {
                        Type = TokenType.ColumnName
                    },
                    Value = this.ParseToken(item.expression())
                }));
            }

            statement.Condition = this.ParseCondition(condition);

            return(statement);
        }
示例#2
0
        public static UpdateQueryInfo VisitUpdateStatement(UpdateStatementContext context)
        {
            var queryInfo = new UpdateQueryInfo
            {
                TableName       = VisitTableName(context.tableName()),
                UpdatedElements = VisitUpdateItem(context.updateItem()),
                WhereExpression = context.expression() != null?
                                  ExpressionVisitor.VisitExpression(context.expression())
                                      : null
            };

            if (context.limitClause() != null)
            {
                var limitClause = context.limitClause();

                if (int.TryParse(limitClause.limit.GetText(), out int limit))
                {
                    queryInfo.Limit = limit;
                }
            }

            return(queryInfo);
        }