private static WhereCondition GenerateStatementNode(SelectSQLParser.WhereStmtContext whereStmt) { var andOr = whereStmt.AND_OR(); var subWhereStmts = whereStmt.whereStmt(); var whereCondition = whereStmt.whereCondition(); if (whereCondition != null && !whereCondition.IsEmpty) //普通单项where条件 return GenerateConditionNode(whereCondition); if (subWhereStmts == null || subWhereStmts.Length<2) throw new MissingWhereConditionException(); //父节点,非单项where条件 var stmtNode = new WhereCondition(WhereConditionNodeType.Statement); var leftWhereStmt = subWhereStmts.First(); var rightWhereStmt = subWhereStmts.Last(); stmtNode.Statement_LeftNode = GenerateStatementNode(leftWhereStmt); stmtNode.Statement_Operator = andOr.GetText(); stmtNode.Statement_RightNode = GenerateStatementNode(rightWhereStmt); return stmtNode; }
private static WhereCondition GenerateConditionNode(SelectSQLParser.WhereConditionContext whereCondition) { var wcInfo = new WhereCondition(WhereConditionNodeType.Condition); wcInfo.Condition_LeftExpression = whereCondition.comparableValue().First().GetText(); wcInfo.Condition_Operator = whereCondition.operators().GetText(); wcInfo.Condition_RightExpression = whereCondition.comparableValue().Last().GetText(); return wcInfo; }