判断SQL语句是否清空缓存 - IsClearCache
2017-03-05 09:55:07 访问(1538) 赞(0) 踩(0)
/// <summary>
/// 是否清空缓存的SQL语句前缀
/// </summary>
public readonly static string[] clearCacheStringArray
=
new string[]
{
"insert",
"update",
"delete",
"truncate"
};
/// <summary>
/// 是否不清空缓存
/// </summary>
/// <param name="sql"></param>
/// <returns></returns>
public static bool IsNotClearCache(string sql)
{
return !IsClearCache(sql);
}
/// <summary>
///
/// sql语句是否带有
/// insert
/// update
/// delete
/// truncate
///
/// 如果有:则返回true,代表需要清空缓存
/// 否则:返回false,不需要清空缓存
///
/// </summary>
/// <param name="sql"></param>
/// <returns></returns>
public static bool IsClearCache(string sql)
{
return IsClearCache(clearCacheStringArray, sql);
}
/// <summary>
///
/// sql语句是否带有
/// insert
/// update
/// delete
/// truncate
///
/// 如果有:则返回true,代表需要清空缓存
/// 否则:返回false,不需要清空缓存
///
/// </summary>
/// <param name="sArray"></param>
/// <param name="sql"></param>
/// <returns></returns>
public static bool IsClearCache(string[] sArray, string sql)
{
if (sArray == null)
return false;
sql = sql.Trim().ToLower();
string[] sPre = new string[]
{
string.Empty,
" ",
"(",
""+'\r'+'\n'
};
string[] sPost = new string[]
{
" ",
""+'\r'+'\n'
};
string sItem = string.Empty;
foreach (string s in sArray)
{
if (s == string.Empty)
continue;
foreach (string sOne in sPre)
{
foreach (string sTwo in sPre)
{
if (sOne == sTwo)
sItem = sOne;
else
sItem = sOne + sTwo;
foreach (string sThree in sPost)
{
if (sql.StartsWith(sItem + s + sThree))
return true;
}
}
}
}
return false;
}
标签:
判断SQL语句是否清空缓存 - IsClearCache 


上一条:
下一条:
相关评论
发表评论