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()); }
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 TestCondition() { SqlMaker <Relation2> package = new SqlMaker <Relation2>(); SqlCondition <Relation2> condition = new SqlCondition <Relation2>(); Assert.Equal("[StudentId] > @StudentId", (condition > "StudentId").ToString()); }
public void TestSelectRelation33() { SqlMaker <Relation> package = new SqlMaker <Relation>(); Assert.Equal("SELECT * FROM `1` AS `V_1_TA` INNER JOIN `关系映射表` AS `V_关系映射表_TB` ON `V_1_TA`.`Sid`=`V_关系映射表_TB`.`StudentId` AND `V_关系映射表_TB`.`Id`=@Id AND `V_关系映射表_TB`.`ClassId`=@ClassId", RelationSql <Student, Relation, Relation, Class> .GetFromTable); Assert.Equal("SELECT * FROM `1` AS `V_1_TA` INNER JOIN `关系映射表` AS `V_关系映射表_TB` ON `V_1_TA`.`Sid`=`V_关系映射表_TB`.`StudentId` AND `V_关系映射表_TB`.`ClassId`=@Cid AND `V_关系映射表_TB`.`Id`=@Id", RelationSql <Student, Relation, Class, Relation> .GetFromSource); }
/// <summary> /// Save into database /// </summary> /// <param name="entries"></param> public void SubmitChanges(List <ResourceEntry> entries, bool deleteRowNotInResource) { SqlMaker gen = new SqlMaker(tname.FormalName) { PrimaryKeys = new string[] { name_column } }; StringBuilder builder = new StringBuilder(); int count = 0; int max = 1000; foreach (var entry in entries) { gen.Clear(); gen.Add(name_column, entry.Name); gen.Add(value_column, entry.NewValue); if (order_column != null) { gen.Add(order_column, entry.Index); } switch (entry.Action) { case DataRowAction.Add: builder.AppendLine(gen.Insert()); break; case DataRowAction.Change: builder.AppendLine(gen.Update()); break; case DataRowAction.Delete: if (deleteRowNotInResource) { builder.AppendLine(gen.Delete()); } break; } count = (count + 1) % max; if (count == 0) { ExecuteNonQuery(); } } ExecuteNonQuery(); void ExecuteNonQuery() { string SQL = builder.ToString(); builder.Clear(); if (!string.IsNullOrEmpty(SQL)) { SqlCmd cmd = new SqlCmd(tname.Provider, SQL); cmd.ExecuteNonQuery(); } } }
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 TestLikeScript3() { SqlMaker <Relation2> package = new SqlMaker <Relation2>(); VasilyProtocal <Relation2> vp = "c%StudentName ^ c+Id-ClassId & c%ClassId "; Assert.Equal("([StudentName] LIKE @StudentName AND [ClassId] LIKE @ClassId) ORDER BY [Id] ASC,[ClassId] DESC", vp.Full); }
public void TestLikeScript2() { SqlMaker <Relation2> package = new SqlMaker <Relation2>(); VasilyProtocal <Relation2> vp = "c % ClassId ^ c+Id-ClassId & c<=Id&(c==StudentName|c!= ClassId)^(3,10) & c%StudentName"; Assert.Equal("((([ClassId] LIKE @ClassId AND [Id] <= @Id) AND ([StudentName] = @StudentName OR [ClassId] <> @ClassId)) AND [StudentName] LIKE @StudentName) ORDER BY [Id] ASC,[ClassId] DESC OFFSET 20 ROW FETCH NEXT 10 rows only", vp.Full); }
public void TestNormalScript3() { SqlMaker <Relation2> package = new SqlMaker <Relation2>(); VasilyProtocal <Relation2> vp = "c+Id-ClassId ^ c<=Id&(c==StudentName|c!= ClassId)^(3,10)"; Assert.Equal("([Id] <= @Id AND ([StudentName] = @StudentName OR [ClassId] <> @ClassId)) ORDER BY [Id] ASC,[ClassId] DESC OFFSET 20 ROW FETCH NEXT 10 rows only", vp.Full); }
private VasilyLink(Type type) { if (!VasilyCache.SqlModelCache.ContainsKey(type)) { SqlAnalyser.Initialization(type); } _model = VasilyCache.SqlModelCache[type]; _maker = new SqlMaker(_model); }
public void TestDeletePreRelation32() { SqlMaker <Relation> package = new SqlMaker <Relation>(); Assert.Equal("DELETE FROM `关系映射表` WHERE `StudentId`=@StudentId", RelationSql <Student, Relation, Relation> .DeletePreFromTable); Assert.Equal("DELETE FROM `关系映射表` WHERE `Id`=@Id", RelationSql <Relation, Relation, Class> .DeletePreFromTable); Assert.Equal("DELETE FROM `关系映射表` WHERE `StudentId`=@Sid", RelationSql <Student, Relation, Class> .DeletePreFromSource); Assert.Equal("DELETE FROM `关系映射表` WHERE `ClassId`=@Cid", RelationSql <Class, Relation, Student> .DeletePreFromSource); }
public void TestSelectRelation32() { SqlMaker <Relation> package = new SqlMaker <Relation>(); Assert.Equal("Id", SqlModel <Relation> .PrimaryKey); Assert.Equal('`', SqlModel <Relation> .Left); Assert.Equal('`', SqlModel <Relation> .Right); Assert.Equal("关系映射表", SqlModel <Relation> .TableName); Assert.NotNull(SqlModel <Relation> .ColumnMapping); }
public void TestRefField() { SqlMaker <Relation2> package = new SqlMaker <Relation2>(); SqlMaker <Class1> package1 = new SqlMaker <Class1>(); Class1 myClass = new Class1(); SqlEntity <Class1> .SetPrimary(myClass, "abc"); Assert.Equal("abc", (string)RelationSql <Class1, Relation2, Student1, Class, Student> .Getters[0](myClass)); }
public void TestUpdateRelation32() { SqlMaker <Relation> package = new SqlMaker <Relation>(); Assert.Equal("UPDATE `关系映射表` SET `StudentId`=@StudentId WHERE `Id`=@Id", RelationSql <Student, Relation, Relation> .ModifyFromTable); //Assert.Equal("UPDATE `关系映射表` SET `Id`=@Id WHERE `ClassId`=@ClassId", RelationSql<Relation, Relation, Class>.ModifyFromTable); Assert.Equal("UPDATE `关系映射表` SET `StudentId`=@Sid WHERE `ClassId`=@Cid", RelationSql <Student, Relation, Class> .ModifyFromSource); Assert.Equal("UPDATE `关系映射表` SET `ClassId`=@Cid WHERE `StudentId`=@Sid", RelationSql <Class, Relation, Student> .ModifyFromSource); }
public void TestValueField() { SqlMaker <Relation2> package = new SqlMaker <Relation2>(); SqlMaker <Class> package1 = new SqlMaker <Class>(); Class myClass = new Class(); SqlEntity <Class> .SetPrimary(myClass, 1); Assert.Equal(1, (int)RelationSql <Class, Relation2, Student1, Student, Class1> .Getters[0](myClass)); }
public void TestRefProperty() { SqlMaker <Relation2> package = new SqlMaker <Relation2>(); SqlMaker <Student1> package1 = new SqlMaker <Student1>(); Student1 student = new Student1(); SqlEntity <Student1> .SetPrimary(student, "abc"); Assert.Equal("abc", (string)RelationSql <Student1, Relation2, Student, Class, Class1> .Getters[0](student)); }
public void TestValueProperty() { SqlMaker <Relation2> package = new SqlMaker <Relation2>(); SqlMaker <Student> package1 = new SqlMaker <Student>(); Student student = new Student(); SqlEntity <Student> .SetPrimary(student, 1); Assert.Equal(1, (int)RelationSql <Student, Relation2, Student1, Class, Class1> .Getters[0](student)); }
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() ); }
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 void Method_CRUD(DataTable dt, Class clss) { var provider = ConnectionProviderManager.DefaultProvider; TableName tname = new TableName(provider, dt.TableName); SqlMaker gen = new SqlMaker(tname.FormalName) { PrimaryKeys = dt.PrimaryKey.Select(x => x.ColumnName).ToArray() }; foreach (DataColumn column in dt.Columns) { string cname = column.ColumnName; gen.Add(cname, "{" + cname + "}"); } Method method = new Method("Insert") { Modifier = Modifier.Public, Type = new TypeInfo(typeof(string)), }; method.Statement.AppendLine("return $\"" + gen.Insert() + "\";"); clss.Add(method); method = new Method("Update") { Modifier = Modifier.Public, Type = new TypeInfo(typeof(string)), }; method.Statement.AppendLine("return $\"" + gen.Update() + "\";"); clss.Add(method); method = new Method("InsertOrUpdate") { Modifier = Modifier.Public, Type = new TypeInfo(typeof(string)), }; method.Statement.AppendLine("return $\"" + gen.InsertOrUpdate() + "\";"); clss.Add(method); method = new Method("Delete") { Modifier = Modifier.Public, Type = new TypeInfo(typeof(string)), }; method.Statement.AppendLine("return $\"" + gen.Delete() + "\";"); clss.Add(method); }
public void TestPageCondition1() { SqlMaker <Relation2> package = new SqlMaker <Relation2>(); SqlCondition <Relation2> c = new SqlCondition <Relation2>(); VasilyProtocal <Relation2> vp = ((c > "StudentId" | c == "ClassId") & c != "ClassName") ^ (2, 10); vp.Instance = new { StudentId = 1, ClassId = 2, ClassName = "abc" }; Assert.Equal( "(([StudentId] > @StudentId OR [ClassId] = @ClassId) AND [ClassName] <> @ClassName) OFFSET 10 ROW FETCH NEXT 10 rows only", vp.Full ); }
private void OperateOnSubmit(RowOperation operation, TEntity entity) { SqlMaker gen = this.Generator; var dict = broker.ToDictionary(entity); gen.AddRange(dict); string sql = null; switch (operation) { case RowOperation.Insert: sql = gen.Insert(); break; case RowOperation.Update: sql = gen.Update(); break; case RowOperation.InsertOrUpdate: sql = gen.InsertOrUpdate(); break; case RowOperation.Delete: sql = gen.Delete(); break; } if (sql == null) { return; } Context.CodeBlock.AppendLine <TEntity>(sql); var evt = new RowEvent { TypeName = typeof(TEntity).Name, Operation = operation, Row = gen.ToDictionary(), }; Context.RowEvents.Add(evt); gen.Clear(); }
public void TestPageCondition2() { SqlMaker <Relation> package = new SqlMaker <Relation>(); SqlCondition <Relation> c = new SqlCondition <Relation>(); VasilyProtocal <Relation> vp = c > "StudentId" | c == "ClassId" & c != "Id" ^ (2, 10); vp.Instance = new { StudentId = 1, ClassId = 2, ClassName = "abc" }; Assert.Equal( "(`StudentId` > @StudentId OR (`ClassId` = @ClassId AND `Id` <> @Id)) LIMIT 10,10", vp.Full ); }
public Demo_Union() { SqlMaker <One> package = new SqlMaker <One>(); condition = new SqlCondition <One>(); }