public static SqlStatement Statement(PlSqlParser.AssignmentStatementContext context) { SqlExpression varRef; if (context.general_element() != null) { var element = ElementNode.Form(context.general_element()); if (element.Argument != null && element.Argument.Length > 0) throw new ParseCanceledException("Invalid assignment: cannot assign a function"); var name = element.Id; if (name.Parent != null) throw new ParseCanceledException("Invalid assignment."); varRef = SqlExpression.VariableReference(name.ToString()); } else if (context.bind_variable() != null) { var varName = Name.Variable(context.bind_variable()); varRef = SqlExpression.VariableReference(varName); } else { throw new ParseCanceledException("Invalid assignment syntax"); } var valueExp = Expression.Build(context.expression()); return new AssignVariableStatement(varRef, valueExp); }
private static LoopControlStatement Build(LoopControlType controlType, PlSqlParser.LabelNameContext labelContext, PlSqlParser.ConditionContext conditionContext) { string label = null; SqlExpression whenExpression = null; if (labelContext != null) label = Name.Simple(labelContext); if (conditionContext != null) whenExpression = Expression.Build(conditionContext.expression()); return new LoopControlStatement(controlType, label, whenExpression); }
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; }