-
/// <summary>
/// Where的Str in/not in查询
/// </summary>
/// <param name="info">数据库表字段</param>
/// <param name="isIn">是否in查询</param>
/// <param name="theList">查询值</param>
public void WhereAddSqlIn8ListIn
(
EntityFieldInfo info,
bool isIn,
List<int> theList
)
{
if (theList == null || theList.Count == 0)
{
throw new Exception
(
"方法:"
+ MethodBase.GetCurrentMethod().ReflectedType.FullName
+ " "
+ MethodBase.GetCurrentMethod().ToString()
+ " 发生异常:"
+ "传入的字符串参数:"
+ "List<int> theList"
+ "为null或为空。"
);
}
string theValue = null;
int iCount = theList.Count;
// 指定个数内的in查询 //
if (iCount <= MaxSqlInNum)
{
switch (iCount)
{
case 1:
theValue = theList[0].ToString();
break;
case 2:
theValue = theList[0].ToString() + "," + theList[1].ToString();
break;
default:
StringBuilder sb = new StringBuilder();
sb.Append(theList[0].ToString());
for (int i = 1; i < iCount; ++i)
{
sb.Append("," + theList[i].ToString());
}
theValue = sb.ToString();
break;
}
m_ListIQueryItem.Add
(
new DataColumnQuerySqlInItem
(
info,
isIn,
theValue
)
);
return;
}
// 超过指定个数的in查询 //
List<string> listStr
=
WhereAddSqlIn6ListInt2Str(theList);
if (listStr == null || listStr.Count == 0)
{
throw new Exception
(
"方法:"
+ MethodBase.GetCurrentMethod().ReflectedType.FullName
+ " "
+ MethodBase.GetCurrentMethod().ToString()
+ " 发生异常:"
+ "传入的字符串参数:"
+ "List<int> theList"
+ "为null或为空。"
);
}
int listCount = listStr.Count;
if (listCount == 1)
{
m_ListIQueryItem.Add
(
new DataColumnQuerySqlInItem
(
info,
isIn,
listStr[0]
)
);
}
else
{
GroupQueryItem gqi
=
new GroupQueryItem(Enums.SqlConditionLink.EmSqlConditionLink.and);
for (int i = 0; i < listCount; ++i)
{
gqi.WhereAddSqlIn
(
SlowX.Core.Enums.SqlConditionLink.EmSqlConditionLink.or,
info,
isIn,
listStr[i]
);
}
AddGroupQueryItem(gqi);
}
}
-
(t.ID in (2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,118,120,122,124,126,128,130,132,134,136,138,140,142,144,146,148,150,152,154,156,158,160,162,164,166,168,170,172,174,176,178,180,182,184,186,188,190,192,194,196,198,200)
or
t.ID in (202,204,206,208,210,212,214,216,218,220,222,224,226,228,230,232,234,236,238,240,242,244,246,248,250,252,254,256,258,260,262,264,266,268,270,272,274,276,278,280,282,284,286,288,290,292,294,296,298,300,302,304,306,308,310,312,314,316,318,320,322,324,326,328,330,332,334,336,338,340,342,344,346,348,350,352,354,356,358,360,362,364,366,368,370,372,374,376,378,380,382,384,386,388,390,392,394,396,398))
-
#region TheSQLGet
/// <summary>
///
/// </summary>
/// <returns></returns>
protected List<int> ListIntBuild()
{
List<int> theResult = new List<int>();
for(int i = 1;i<200;++i)
{
theResult.Add(i * 2);
}
return theResult;
}
/// <summary>
/// 获得输出的SQL语句
/// </summary>
/// <param name="xdbHelper"></param>
/// <returns></returns>
protected override string TheSQLGet(DBHelper xdbHelper)
{
#region 逻辑代码
string theResult = null;
// 标识是否创建或打开数据库链接 //
bool bIsCreate = true;
if (xdbHelper == null)
{
// 如果 xdbHelper 为null //
// 则new一个数据库操作实体 //
xdbHelper
=
SlowX.DAL.Helpers.DBHelper.CreateDBHelper();
}
else
{
// 如果 xdbHelper 不为null //
// 判断 xdbHelper是否打开链接 //
// 相当于是否执行 xdbHelper.OpenDBHelper(); //
bIsCreate = xdbHelper.IsNotOpen();
}
try
{
if (bIsCreate)
{
// 没有打开,则打开链接 //
xdbHelper.OpenDBHelper();
}
// 业务逻辑操作实体 //
// insert/update/delete等操作 //
SlowX.ExamLib.Business.UTB_EXAM_STUDENT
bll
=
SlowX.ExamLib.Business.UTB_EXAM_STUDENT.instance;
// 组合SQL的逻辑实体 //
SlowX.ExamLib.Entity.UTB_EXAM_STUDENT
entity
=
new SlowX.ExamLib.Entity.UTB_EXAM_STUDENT();
IWhereDriver iwhere = entity;
// 构建测试数据 //
List<int> intList = ListIntBuild();
// ===调用代码=== //
iwhere.WhereAddSqlIn8ListIn(entity._ID, true, intList);
// 执行List操作 //
// 这里做DEMO,仅打印输出的SQL语句 //
// bll.List(entity, xdbHelper);
theResult
=
bll.i_iBuildSQL.BuildSqlList(entity, xdbHelper);
if (bIsCreate)
{
// 关闭数据库链接 //
// 如果用了事务,提交数据库链接 //
xdbHelper.EndDBHelper();
}
}
catch (Exception err)
{
if (bIsCreate)
{
// 关闭数据库链接 //
// 如果用了事务,回滚数据库链接 //
xdbHelper.TranDBHelper();
}
throw err;
}
finally
{
if (bIsCreate)
{
// 判断数据库操作是否正确关闭 //
// 如果没有正确关闭,则关闭并抛出异常提示代码缺陷 //
xdbHelper.FinallyDBHelper();
}
}
return theResult;
#endregion 逻辑代码
}
#endregion TheSQLGet
-
select
t.ID, t.TheName, t.ClassId,
t.CreateTime, t.UpdateTime
from UTB_EXAM_STUDENT t
where (t.ID in (2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,118,120,122,124,126,128,130,132,134,136,138,140,142,144,146,148,150,152,154,156,158,160,162,164,166,168,170,172,174,176,178,180,182,184,186,188,190,192,194,196,198,200)
or
t.ID in (202,204,206,208,210,212,214,216,218,220,222,224,226,228,230,232,234,236,238,240,242,244,246,248,250,252,254,256,258,260,262,264,266,268,270,272,274,276,278,280,282,284,286,288,290,292,294,296,298,300,302,304,306,308,310,312,314,316,318,320,322,324,326,328,330,332,334,336,338,340,342,344,346,348,350,352,354,356,358,360,362,364,366,368,370,372,374,376,378,380,382,384,386,388,390,392,394,396,398))