public void TestCondition() { SqlMaker <Relation2> package = new SqlMaker <Relation2>(); SqlCondition <Relation2> condition = new SqlCondition <Relation2>(); Assert.Equal("[StudentId] > @StudentId", (condition > "StudentId").ToString()); }
public void TestCondition2() { SqlMaker <Relation2> package = new SqlMaker <Relation2>(); SqlCondition <Relation2> condition = new SqlCondition <Relation2>(); Assert.Equal("([StudentId] > @StudentId OR [ClassId] <> @ClassId)", (condition > "StudentId" | condition != "ClassId").ToString()); }
bool CompareConditions(SqlCondition cond1, SqlCondition cond2) { if (cond1.ElementType != cond2.ElementType) { return(false); } if (cond1.Predicate.ElementType != cond2.Predicate.ElementType) { return(false); } switch (cond1.Predicate.ElementType) { case QueryElementType.IsNullPredicate: { var isNull1 = (SqlPredicate.IsNull)cond1.Predicate; var isNull2 = (SqlPredicate.IsNull)cond2.Predicate; return(isNull1.IsNot == isNull2.IsNot && CompareExpressions(isNull1.Expr1, isNull2.Expr1) == true); } case QueryElementType.ExprExprPredicate: { var expr1 = (SqlPredicate.ExprExpr)cond1.Predicate; var expr2 = (SqlPredicate.ExprExpr)cond2.Predicate; return(CompareExpressions(expr1, expr2)); } } return(false); }
internal SqlConditionRelation(SqlCondition cond1, SqlCondition cond2, SqlLogicOper logicOper) { _cond1 = cond1; _cond2 = cond2; _logicOper = logicOper; }
public void Test_3() { var condition2 = new SqlCondition("Age>@Age"); var condition = new OrCondition(null, condition2); Assert.Equal("Age>@Age", condition.GetCondition()); }
public void TestLikeCondition2() { SqlMaker <Relation2> package = new SqlMaker <Relation2>(); SqlCondition <Relation2> condition = new SqlCondition <Relation2>(); Assert.Equal("(([StudentId] LIKE @StudentId AND [StudentId] > @StudentId) AND [StudentId] LIKE @StudentId)", ("StudentId" % condition & condition > "StudentId" & condition % "StudentId").ToString()); }
public void Test_4() { var condition1 = new SqlCondition("Name=@Name"); var condition = new OrCondition(condition1, null); Assert.Equal("Name=@Name", condition.GetCondition()); }
public override string ToString() { if (SqlCondition.HasValue()) { return(SqlCondition); } return($"({Left}-{Operator}-{Right})"); }
public void TestUnionCondition3() { SqlMaker <Student> package = new SqlMaker <Student>(); SqlCondition <Student> condition = new SqlCondition <Student>(); var result = SqlCollection <Student> .TableIntersect(SqlEntity <Student> .SelectAllWhere + (condition > "Sid").Full, "table1", "table2", "table3"); Assert.Equal("(SELECT * FROM `table1` WHERE `Sid` > @Sid) INTERSECT (SELECT * FROM `table2` WHERE `Sid` > @Sid) INTERSECT (SELECT * FROM `table3` WHERE `Sid` > @Sid)", result); }
public void TestUnionCondition2() { SqlMaker <Student> package = new SqlMaker <Student>(); SqlCondition <Student> condition = new SqlCondition <Student>(); var result = SqlCollection <Student> .Union(SqlEntity <Student> .SelectAllWhere + (condition > "Sid").Full); Assert.Equal("(SELECT * FROM `1` WHERE `Sid` > @Sid)", result); }
public void TestUnionCondition2() { SqlPackage <Student> package = new SqlPackage <Student>(); SqlCondition <Student> condition = new SqlCondition <Student>(); var result = SqlUnion <Student> .Union(Sql <Student> .SelectAllByCondition + (condition > "Sid").Full); Assert.Equal("SELECT * FROM `1` WHERE Sid > @Sid", result); }
public void TestUnionCondition1() { SqlPackage <Student> package = new SqlPackage <Student>(); SqlCondition <Student> condition = new SqlCondition <Student>(); var result = SqlUnion <Student> .Union(Sql <Student> .SelectAllByCondition + (condition > "Sid").Full, "table1", "table2", "table3"); Assert.Equal("SELECT * FROM `table1` WHERE Sid > @Sid UNION SELECT * FROM `table2` WHERE Sid > @Sid UNION SELECT * FROM `table3` WHERE Sid > @Sid", result); }
public void Test_2() { var condition1 = new SqlCondition("Name=@Name"); var condition2 = new SqlCondition("Age=@Age"); var condition = new OrCondition(condition1, condition2); Assert.Equal("(Name=@Name Or Age=@Age)", condition.GetCondition()); }
public void Test_2() { var condition1 = new SqlCondition("Name=@Name"); var condition2 = new SqlCondition("Age>@Age"); var condition = new AndCondition(condition1, condition2); Assert.Equal("Name=@Name And Age>@Age", condition.GetCondition()); }
/// <summary> /// 过滤条件 /// </summary> /// <param name="name">列名</param> /// <param name="value">值</param> /// <param name="operator">运算符</param> public ISqlBuilder Filter(string name, object value, Operator @operator = Operator.Equal) { if (!IsValid(name, value)) { return(this); } And(SqlCondition.Create(name, GetParamPrefix(), @operator)); AddParam(name, value, @operator); return(this); }
/// <summary> /// 添加In过滤条件 /// </summary> private void AddIn(StringBuilder result, string name, object value, int index) { if (!IsValid(name, value)) { return; } var paramName = SqlCondition.GetParamName(string.Format("{0}{1}", name, index)); result.AppendFormat("{0}{1},", GetParamPrefix(), paramName); _params.Add(paramName, value); }
public static SqlCP Condition(this object instance, SqlCondition condition) { SqlCP cp = new SqlCP(); cp.Instance = instance; cp.Query = condition.Query; cp.Tails = condition.Tails; cp.Order = condition.Order; condition.Claer(); return(cp); }
/// <summary> /// Returns a string that represents this instance. /// </summary> public override string ToString() { if (SqlCondition.HasValue()) { return(SqlCondition); } var valueText = Value == null ? NULL_ESCAPE : GetSerializedValue().Replace(":", COLON_ESCAPE); return(string.Join(":", PropertyName, FilterFunction, valueText)); }
public string this[SqlCondition index] { get { return(mConditionMapping[index]); } set { mConditionMapping[index] = value; } }
public override ISqlExpression GetSubQuery(IBuildContext context) { if (_subQuerySql == null) { var cond = new SqlCondition( _methodCall.Method.Name == "All", new SqlPredicate.FuncLike(SqlFunction.CreateExists(SelectQuery))); _subQuerySql = new SqlSearchCondition(cond); } return(_subQuerySql); }
public DbExpression(DbColumn column, DbSelectStatement select_clause, SqlCondition condition) { mColumn = column; mFieldvalue = select_clause; mCondition = condition; this[SqlCondition.IsEqual] = "="; this[SqlCondition.IsLessEqual] = "<="; this[SqlCondition.IsGreaterEqual] = ">="; this[SqlCondition.IsLess] = "<"; this[SqlCondition.IsGreater] = ">"; this[SqlCondition.Like] = "LIKE"; }
public DbExpression(DbColumn column, DbFieldEntry fieldvalue, SqlCondition condition) { mColumn = column; mFieldvalue = fieldvalue; mCondition = condition; this[SqlCondition.IsEqual] = "="; this[SqlCondition.IsLessEqual] = "<="; this[SqlCondition.IsGreaterEqual] = ">="; this[SqlCondition.IsLess] = "<"; this[SqlCondition.IsGreater] = ">"; this[SqlCondition.Like] = "LIKE"; }
public void TestCondition3() { SqlPackage <Relation2> package = new SqlPackage <Relation2>(); SqlCondition <Relation2> c = new SqlCondition <Relation2>(); Assert.Equal( "((StudentId > @StudentId OR ClassId = @ClassId) AND ClassName <> @ClassName)", ((c > "StudentId" | c == "ClassId") & c != "ClassName").ToString() ); }
public void TestCondition3() { SqlMaker <Relation2> package = new SqlMaker <Relation2>(); SqlCondition <Relation2> c = new SqlCondition <Relation2>(); Assert.Equal( "(([StudentId] > @StudentId OR [ClassId] = @ClassId) AND [ClassName] <> @ClassName)", ((c > "StudentId" | c == "ClassId") & c != "ClassName").ToString() ); }
/// <summary> /// 使用Or连接条件 /// </summary> /// <param name="condition">过滤条件</param> public ISqlBuilder Or(string condition) { if (condition.IsEmpty()) { return(this); } if (_condition == null) { _condition = SqlCondition.Create(condition); return(this); } _condition = new OrCondition(_condition.GetCondition(), condition); return(this); }
public void TestPageCondition3() { SqlPackage <Relation2> package = new SqlPackage <Relation2>(); SqlCondition <Relation2> c = new SqlCondition <Relation2>(); Assert.Equal( "((StudentId > @StudentId OR ClassId = @ClassId) AND ClassName <> @ClassName) ORDER BY StudentId ASC,ClassId DESC", //升序-----------降序-----排序链接-----------------条件---------------------------- //↓ ↓ ↓ (c + "StudentId" - "ClassId" ^ (c > "StudentId" | c == "ClassId") & c != "ClassName").ToString() ); }
public void TestPageCondition3() { SqlMaker <Relation2> package = new SqlMaker <Relation2>(); SqlCondition <Relation2> c = new SqlCondition <Relation2>(); Assert.Equal( "(([StudentId] > @StudentId OR [ClassId] = @ClassId) AND [ClassName] <> @ClassName) ORDER BY [StudentId] ASC,[ClassId] DESC", //升序-----------降序-----排序链接-----------------条件---------------------------- //↓ ↓ ↓ (c + "StudentId" - "ClassId" ^ (c > "StudentId" | c == "ClassId") & c != "ClassName").ToString() ); }
public override ISqlExpression GetSubQuery(IBuildContext?context) { if (_subQuerySql == null) { var cond = new SqlCondition( _methodCall.Method.Name.StartsWith("All"), new SqlPredicate.FuncLike(SqlFunction.CreateExists(SelectQuery))); Sequence.CompleteColumns(); _subQuerySql = new SqlSearchCondition(cond); } return(_subQuerySql); }
public void TestOrderCondition2() { SqlPackage <Relation2> package = new SqlPackage <Relation2>(); SqlCondition <Relation2> c = new SqlCondition <Relation2>(); Assert.Equal( "((StudentId > @StudentId OR ClassId = @ClassId) AND ClassName <> @ClassName) ORDER BY StudentId ASC", //----------------------------条件----------------排序链接--升序------------ // ↓ ↓ ((c > "StudentId" | c == "ClassId") & c != "ClassName" ^ c + "StudentId").ToString() ); }
private void Clear(SqlCondition condition) { if (_condList.Contains(condition)) { _condList.Remove(condition); } if (condition.GetType() == typeof(SqlConditionRelation)) { SqlConditionRelation richCond = (SqlConditionRelation)condition; this.Clear(richCond._cond1); this.Clear(richCond._cond2); } }