public ConditionPair(string left, Operand operand, RightOptType rightIsValue, object rightValue) { Console.WriteLine("带参数初始化构造函数构造成功(无嵌套)"); this.left = left; this.operand = operand; this.rightValType = rightIsValue; this.rightValue = rightValue; }
public ConditionPair(string left, Operand operand, RightOptType rightIsValue, Table table) { Console.WriteLine("带参数初始化构造函数构造成功(有嵌套)"); this.left = left; this.operand = operand; this.rightValType = rightIsValue; this.rightTable = table; this.rightValueList = table.getColumn(left); //需增加一个异常捕获 }
//初始构造函数 public Condition(Table table, string condition, List <Table> nestedTable = null) { if (condition == null || condition.Equals("")) { this.isDefault = 0; } else { this.isDefault = 1; this.conditions = new List <ConditionPair>(); //this.columnName = new Dictionary<string, int>(); this.table = table; this.strs = condition.Split(' '); //int columnIndex = 0; int nestedIndex = 0; for (int i = 0; i < strs.Length; i++) { if (strs[i].Equals("in")) { Console.WriteLine(strs[i - 1] + " " + strs[i] + " " + strs[i + 1]); string param1 = strs[i - 1]; string param2 = strs[i]; string param3 = strs[i + 1].TrimStart('\"').TrimEnd('\"'); Operand opt = Condition.getOperand(param2); RightOptType type = Condition.getType(param3, opt); if (nestedIndex < nestedTable.Count) { this.conditions.Add(new ConditionPair(param1, opt, type, nestedTable[nestedIndex])); nestedIndex++; //if (!this.columnName.ContainsKey(param1)) //{ // this.columnName.Add(param1, columnIndex++); //} } else { throw new Exception("嵌套Table数量不正确"); } strs[i - 1] = " "; strs[i] = "?"; strs[i + 1] = " "; } else if (strs[i].Equals("==") || strs[i].Equals("!=") || strs[i].Equals(">") || strs[i].Equals(">=") || strs[i].Equals("<") || strs[i].Equals("<=")) { Console.WriteLine(strs[i - 1] + " " + strs[i] + " " + strs[i + 1]); string param1 = strs[i - 1]; string param2 = strs[i]; string param3 = strs[i + 1].TrimStart('\"').TrimEnd('\"'); Operand opt = Condition.getOperand(param2); RightOptType type = Condition.getType(param3, opt); this.conditions.Add(new ConditionPair(param1, opt, type, type == RightOptType.CONSTANT ? convertType(param1, param3) : param3)); //if (!this.columnName.ContainsKey(param1)) //{ // this.columnName.Add(param1, columnIndex++); //} //Console.WriteLine(type); //if (type.Equals(RightOptType.FIELD)) //{ // this.columnName.Add(param3, columnIndex++); //} strs[i - 1] = " "; strs[i] = "?"; strs[i + 1] = " "; } else if (strs[i].Equals("or")) { strs[i] = "+"; } else if (strs[i].Equals("and")) { strs[i] = "*"; } } } }