/// <summary> /// /// </summary> /// <param name="sq"></param> /// <param name="gVal"></param> /// <param name="condition"></param> private void buildCaseCondition(Syntax.SQuery sq, string[] gVal, int condition, string caseValue) { foreach (string s in gVal) { var ss = ""; string[] items; ss = s; items = splitWithSpace(ss).ToArray(); var oper = WhereOperators.none; var fld = ""; var val = ""; //foreach (string it in items) //{ if (items.Length == 1) { if (items[0].ToLower() == "else") { oper = WhereOperators.defaults; } sq.And("", fld, val, oper, caseValue); } else if (items.Length == 3) { val = items[2]; fld = items[0]; oper = scanOperator(items[1]); if (oper == WhereOperators.none) { //add error } sq.And("", fld, val, oper, caseValue); } else { AddError(Source.Severity.Error, "case structure invalid. please check your code"); } // } } }
/// <summary> /// /// </summary> /// <param name="sq"></param> /// <param name="gVal"></param> /// <param name="condition">and-1, or-2</param> private void buildAndorCondition(Syntax.SQuery sq, string[] gVal, int condition) { foreach (string s in gVal) { var ss = ""; string[] items; ss = s.Replace("(", "").ToString().Replace(")", ""); items = Regex.Split(ss, @"\s+").Where(x => x != string.Empty).ToArray(); var oper = WhereOperators.none; bool isleft = false; string lefttb = ""; string leftfld = ""; string righttb = ""; string rightfld = ""; string val = ""; foreach (string it in items) { if (Scan(QueryDefination.getFields, it)) // check table field { var tf = split(":", it); if (tf.Length == 2 && tf[0].ToLower() != "value") { if (isleft == false) { isleft = true; lefttb = tf[0]; if (tf[1] != "") { leftfld = tf[1]; } else { //throw exception } } else { righttb = tf[0]; if (tf[1] != "") { rightfld = tf[1]; } else { //throw exception } } } else if (tf[0].ToLower() == "value") { val = tf[1]; } else { //throw exception } } else { oper = scanOperator(it); if (oper == WhereOperators.none) { //throw error unknow expression here } } } if (condition == 1) { if (val != "") { sq.And(lefttb, leftfld, val, oper); } else { sq.And(lefttb, leftfld, righttb, rightfld, oper); } } else { if (val != "") { sq.Or(lefttb, leftfld, val, oper); } else { sq.Or(lefttb, leftfld, righttb, rightfld, oper); } } } }