public override void EnterColumn(SelectSQLParser.ColumnContext context) { Column column = new Column(); if (context.columnExpression().IsEmpty) //不存在列表达式 throw new MissingColumnExpressionException(); var functionalColumn = context.columnExpression().functionableColumn(); var columnName = context.columnExpression().columnName(); if (functionalColumn!=null&&!functionalColumn.IsEmpty) { column.Expression = new ColumnExpression(ExpressionType.Function); column.Expression.Function = new FunctionDescription(); } else if (columnName!=null&&!columnName.IsEmpty) { column.Expression = new ColumnExpression(ExpressionType.ColumnName); column.Expression.ColumnName = columnName.GetText(); } else { throw new MissingColumnExpressionException(); } if (context.AS() != null) //存在别名 { columnName = context.columnName(); if (columnName.IsEmpty) //语法错误 throw new MissingColumnAliasException(); column.HasAlias = true; column.Alias = columnName.GetText(); } this.SelectStmt.Columns.Add(column); }
public override void EnterOrderByStmt(SelectSQLParser.OrderByStmtContext context) { var orderBy = new OrderByCondition(); var expression = context.columnExpression(); if (expression == null || expression.IsEmpty) throw new MissingOrderByException(); orderBy.Expression = expression.GetText(); if (string.IsNullOrEmpty(orderBy.Expression)) throw new MissingOrderByException(); orderBy.Direction = OrderByDirection.DESC; var direction = context.orderByDirection(); if (direction == null || direction.IsEmpty) orderBy.Direction = OrderByDirection.ASC; else if(direction.GetText().Equals("asc", StringComparison.OrdinalIgnoreCase)) orderBy.Direction = OrderByDirection.ASC; this.SelectStmt.OrderBy.Add(orderBy); }