MySQL读取不重复的数据,读取之前可以判断一下IsRead是0,0表示可以读取,1表示不可读取,读取失败需要释放掉改为0,方便第二次读取;
核心方法:
/// <summary>
/// 获取并更新IsRed
/// </summary>
/// <param name="SceneCode"></param>
/// <param name="IsRead"></param>
/// <returns></returns>
public McAutoscenetask GetByIsRedModel(string SceneCode, int IsRed)
{
var dic = new StatementParameterCollection();
StringBuilder sbSql = new StringBuilder();
sbSql.Append("start transaction;select * from mc_autoscenetask
where SceneCode=@SceneCode for update;update mc_autoscenetask set IsRead=@IsRead
where SceneCode=@SceneCode;commit;");
dic.AddInParameter("@SceneCode", DbType.String, SceneCode);
dic.AddInParameter("@IsRead", DbType.Int32, IsRed);
return baseDao.SelectFirst<McAutoscenetask>(sbSql.ToString(), dic);
}
希望以上分享对初学朋友有些帮助,谢谢!
更多关注付义方技术博客:http://blog.csdn.net/fuyifang
或者直接用手机扫描二维码查看更多博文:
时间: 2024-09-24 23:00:56