public void ParseAllSqls() { var tt = @"/*use his*/ select * from t1 where time between '{Start}' and '{End}' /*use his_bak*/ delete from t2 where time between '{Start}' and '{End}'; /*use his_bak*/ insert t2; "; var cs = SqlSection.ParseAll(tt); Assert.NotNull(cs); Assert.Equal(3, cs.Length); Assert.Equal("his", cs[0].ConnName); Assert.Equal(SqlActions.Query, cs[0].Action); Assert.Equal("select * from t1 where time between '{Start}' and '{End}'", cs[0].Sql); Assert.Equal("his_bak", cs[1].ConnName); Assert.Equal(SqlActions.Execute, cs[1].Action); Assert.Equal("delete from t2 where time between '{Start}' and '{End}'", cs[1].Sql); Assert.Equal("his_bak", cs[2].ConnName); Assert.Equal(SqlActions.Insert, cs[2].Action); Assert.Equal("insert t2", cs[2].Sql); }
/// <summary>执行</summary> /// <param name="ctx"></param> /// <returns></returns> protected override Int32 Execute(JobContext ctx) { //var sqls = ctx.Task.Data as String; var sqls = Job.Data; sqls = TemplateHelper.Build(sqls, ctx.Task.Start, ctx.Task.End); // 向调度中心返回解析后的Sql语句 ctx.Remark = sqls; var sections = SqlSection.ParseAll(sqls); if (sections.Length == 0) { return(-1); } var rs = ExecuteSql(sections, ctx, (section, dt) => SqlMessage.ProduceMessage(dt, ctx)); return(rs); }