private void SerializeSelectColumns(IEnumerable <SelectColumn> selectColumns, BinaryWriter writer) { var list = selectColumns == null ? new List <SelectColumn>() : selectColumns.ToList(); writer.Write(list.Count); for (int i = 0; i < list.Count; i++) { var column = list[i]; SelectColumn.Serialize(column, writer); } }
private IEnumerable <SelectColumn> DeserializeSelectColumns(BinaryReader reader) { var count = reader.ReadInt32(); var columns = new SelectColumn[count]; for (int i = 0; i < count; i++) { columns[i] = SelectColumn.Deserialize(reader); } return(columns); }
/// <summary> /// /// </summary> /// <param name="query"></param> /// <returns></returns> public virtual SqlExpression VisitQuery(SqlQueryExpression query) { var selectColumns = new List <SelectColumn>(); foreach (var column in query.SelectColumns) { var newColumn = new SelectColumn(Visit(column.Expression), column.Alias); newColumn.InternalName = column.InternalName; newColumn.ResolvedName = column.ResolvedName; selectColumns.Add(newColumn); } var newQuery = new SqlQueryExpression(selectColumns); if (query.FromClause != null) { newQuery.FromClause = VisitFromClause(query.FromClause); } if (query.WhereExpression != null) { newQuery.WhereExpression = Visit(query.WhereExpression); } if (query.HavingExpression != null) { newQuery.HavingExpression = Visit(query.HavingExpression); } if (query.GroupBy != null) { newQuery.GroupBy = VisitExpressionList(newQuery.GroupBy.ToArray()); } newQuery.GroupMax = query.GroupMax; newQuery.Distinct = query.Distinct; if (query.NextComposite != null) { var visitedComposite = Visit(query.NextComposite); if (visitedComposite.ExpressionType == SqlExpressionType.Query) { newQuery.NextComposite = (SqlQueryExpression)visitedComposite; } newQuery.CompositeFunction = query.CompositeFunction; newQuery.IsCompositeAll = query.IsCompositeAll; } return(query); }
/// <summary> /// /// </summary> /// <param name="query"></param> /// <returns></returns> public virtual SqlExpression VisitQuery(SqlQueryExpression query) { var selectColumns = new List<SelectColumn>(); foreach (var column in query.SelectColumns) { var newColumn = new SelectColumn(Visit(column.Expression), column.Alias); newColumn.InternalName = column.InternalName; newColumn.ResolvedName = column.ResolvedName; selectColumns.Add(newColumn); } var newQuery = new SqlQueryExpression(selectColumns); if (query.FromClause != null) newQuery.FromClause = VisitFromClause(query.FromClause); if (query.WhereExpression != null) newQuery.WhereExpression = Visit(query.WhereExpression); if (query.HavingExpression != null) newQuery.HavingExpression = Visit(query.HavingExpression); if (query.GroupBy != null) newQuery.GroupBy = VisitExpressionList(newQuery.GroupBy.ToArray()); newQuery.GroupMax = query.GroupMax; newQuery.Distinct = query.Distinct; if (query.NextComposite != null) { var visitedComposite = Visit(query.NextComposite); if (visitedComposite.ExpressionType == SqlExpressionType.Query) newQuery.NextComposite = (SqlQueryExpression) visitedComposite; newQuery.CompositeFunction = query.CompositeFunction; newQuery.IsCompositeAll = query.IsCompositeAll; } return query; }
public void SelectSingleColumn(SelectColumn col) { selectedColumns.Add(col); }
private SelectColumn PrepareColumn(SelectColumn column, IRequest context, IList<SelectColumn> functionColumns, ref int aggregateCount) { if (column.Expression is SqlQueryExpression) throw new InvalidOperationException("Sub-query expressions are invalid in select columns."); SelectColumn newColumn; var exp = column.Expression; if (exp != null) exp = exp.Prepare(fromSet.ExpressionPreparer); if (exp is SqlReferenceExpression) { var sqlRef = (SqlReferenceExpression) exp; var colName = sqlRef.ReferenceName; ObjectName resolvedName = null; var alias = column.Alias; if (String.IsNullOrEmpty(alias)) { resolvedName = colName; } else { resolvedName = new ObjectName(alias); } newColumn = new SelectColumn(exp, alias) { InternalName = colName, ResolvedName = resolvedName }; } else { var funcAlias = functionColumns.Count.ToString(CultureInfo.InvariantCulture); if (column.Expression.HasAggregate(context)) { aggregateCount++; funcAlias += "_A"; } var alias = column.Alias; if (string.IsNullOrEmpty(alias)) alias = exp.ToString(); newColumn = new SelectColumn(exp, alias) { InternalName = new ObjectName(FunctionTableName, funcAlias), ResolvedName = new ObjectName(alias) }; functionColumns.Add(newColumn); } return newColumn; }
private void AddAllFromTable(IFromTableSource table) { // Select all the tables var columns = table.ColumnNames; foreach (ObjectName name in columns) { // Make up the SelectColumn SqlExpression e = SqlExpression.Reference(name); var column = new SelectColumn(e) { ResolvedName = name, InternalName = name }; // Add to the list of columns selected SelectSingleColumn(column); } }
/* Checks for whatever follows SELECT */ public void SelectList(ICollection<SelectColumn> columns) { SelectColumn column; switch ((mcc_ntk==-1)?mcc_mntk():mcc_ntk) { case 166: mcc_consume_token(166); column = new SelectColumn(Expression.Constant(ParserUtil.String("*"))); columns.Add(column); break; default: mcc_la1[152] = mcc_gen; if (mcc_2_27(1)) { column = SelectItem(); columns.Add(column); while (true) { switch ((mcc_ntk==-1)?mcc_mntk():mcc_ntk) { case 156: ; break; default: mcc_la1[151] = mcc_gen; goto label_26; } mcc_consume_token(156); column = SelectItem(); columns.Add(column); }label_26: ; } else { mcc_consume_token(-1); throw new ParseException(); } break; } }
public static SelectColumn BuildColumn(PlSqlParser.SelectedElementContext context) { string alias = null; if (context.column_alias() != null && !context.column_alias().IsEmpty) { alias = Name.Simple(context.column_alias()); } SelectColumn column; if (context.expression() != null && !context.expression().IsEmpty) { column = new SelectColumn(Expression.Build(context.expression()), alias); } else if (context.selectedColumn() != null && !context.selectedColumn().IsEmpty) { bool glob = context.selectedColumn().glob != null; ObjectName name = Name.Select(context.selectedColumn().objectName(), glob); var exp = SqlExpression.Reference(name); column = new SelectColumn(exp, alias); } else { throw new ParseCanceledException(); } return column; }