public void AppendFormat_Test() { var query = new SqlString(); query.AppendFormat("Hello{0}", 123); query.AppendFormat("World{0}", 456); Assert.AreEqual("Hello123World456", query); }
/// <summary> /// 分页获取集合 /// </summary> public List <TWO_ORDER> GetListPage(ref PagerModel pager, string name, DateTime startTime, DateTime endTime, int?status) { SqlString sql = new SqlString(string.Format(@" select * from two_order t where 1=1 and DEL_FLAG='{0}'", "0")); sql.AppendSql(@" and ( ORDER_TIME>=STR_TO_DATE(@startTime, '%Y-%m-%d %H:%i:%s') and ORDER_TIME<=STR_TO_DATE(@endTime, '%Y-%m-%d %H:%i:%s') )", startTime.ToString("yyyy-MM-dd HH:mm:ss"), endTime.ToString("yyyy-MM-dd HH:mm:ss")); if (!string.IsNullOrWhiteSpace(name)) { sql.AppendSql(" and PRISONER_NAME like @name", "%" + name + "%"); } if (status != null) { sql.AppendSql(" and T_STATUS = @status", status); } if (status != null) { sql.AppendFormat(" and T_STATUS = '{0}'", status); //测试追加非参数化SQL } sql.AppendSql(" and 1=1"); //测试没有参数 string orderby = "order by ORDER_TIME desc, ID asc"; //测试排序 pager = DBHelper.FindPageBySql <TWO_ORDER>(sql.SQL, orderby, pager.rows, pager.page, sql.Params); return(pager.result as List <TWO_ORDER>); }