本文整理汇总了C#中SelectCommand.GetCommandText方法的典型用法代码示例。如果您正苦于以下问题:C# SelectCommand.GetCommandText方法的具体用法?C# SelectCommand.GetCommandText怎么用?C# SelectCommand.GetCommandText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SelectCommand
的用法示例。
在下文中一共展示了SelectCommand.GetCommandText方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InternalGetPagerCommand
/// <summary>
/// 获取选择语句内容
/// </summary>
/// <param name="baseCommand">源选择语句</param>
/// <param name="orderReverse">是否反转排序</param>
/// <returns>选择语句内容</returns>
internal static String InternalGetPagerCommand(SelectCommand baseCommand, Boolean orderReverse)
{
SqlCommandBuilder sb = new SqlCommandBuilder(baseCommand.Database);
sb.AppendSelectPrefix();
sb.AppendSelectDistinct(baseCommand.UseDistinct).AppendAllColumnNames(baseCommand.QueryFields);
if (baseCommand.PageSize > 0 && baseCommand.RecordStart > 0)//分页模式
{
/*
SELECT * FROM
(
SELECT *, ROWNUM RN
FROM (SELECT * FROM TABLE_NAME)
WHERE ROWNUM <= 30
)
WHERE RN > 20
*/
SelectCommand innestCommand = new SelectCommand(baseCommand.Database, baseCommand.TableName);
innestCommand.QueryFields = baseCommand.QueryFields;
innestCommand.SqlJoins = baseCommand.SqlJoins;
innestCommand.SqlWhere = baseCommand.SqlWhere;
innestCommand.GroupByColumns = baseCommand.GroupByColumns;
innestCommand.SqlHaving = baseCommand.SqlHaving;
innestCommand.SqlOrders = baseCommand.SqlOrders;
SelectCommand innerCommand = new SelectCommand(baseCommand.Database, innestCommand, "");
innerCommand.SqlWhere = SqlCondition.LessThanOrEqualColumn(innerCommand, "ROWNUM", (baseCommand.RecordStart + baseCommand.PageSize).ToString());
innerCommand.InternalQuerys(baseCommand.QueryFields.ToArray());
innerCommand.InternalQuerys(SqlQueryField.InternalCreateFromFunction(baseCommand, "ROWNUM", "RN"));
sb.AppendSelectFrom(innerCommand.GetCommandText(), true);
sb.AppendWhere(SqlCondition.GreaterThanColumn(baseCommand, "RN", baseCommand.RecordStart.ToString()));
}
else//正常模式
{
sb.AppendSelectFromAndJoins(baseCommand.TableName, baseCommand.IsFromSql, baseCommand.SqlJoins);
ISqlCondition where = baseCommand.SqlWhere;
if (baseCommand.PageSize > 0)
{
where = SqlCondition.And(baseCommand, where, SqlCondition.LessThanOrEqualColumn(baseCommand, "ROWNUM", baseCommand.PageSize.ToString()));
}
sb.AppendWhere(where);
sb.AppendSelectGroupBys(baseCommand.GroupByColumns);
sb.AppendHaving(baseCommand.SqlHaving);
sb.AppendSelectOrderBys(baseCommand.SqlOrders, orderReverse);
}
return sb.ToString();
}
示例2: InternalGetPagerCommand
/// <summary>
/// 获取选择语句内容
/// </summary>
/// <param name="baseCommand">源选择语句</param>
/// <param name="orderReverse">是否反转排序</param>
/// <returns>选择语句内容</returns>
internal static String InternalGetPagerCommand(SelectCommand baseCommand, Boolean orderReverse)
{
SqlCommandBuilder sb = new SqlCommandBuilder(baseCommand.Database);
sb.AppendSelectPrefix();
if (baseCommand.PageSize > 0 && baseCommand.RecordStart > 0)//分页模式
{
/*
SELECT * FROM
(
SELECT TOP 30 *, ROW_NUMBER() OVER(ORDER BY ID ASC) AS RN
FROM TABLE_NAME
) AS T
WHERE RN > 20
*/
sb.AppendSelectDistinct(baseCommand.UseDistinct).AppendAllColumnNames(baseCommand.QueryFields);
SqlCommandBuilder innerBuilder = new SqlCommandBuilder(baseCommand.Database);
innerBuilder.AppendSelectOrderBys(baseCommand.SqlOrders, false);
SelectCommand innerCommand = new SelectCommand(baseCommand.Database, baseCommand.TableName);
innerCommand.InternalQuerys(baseCommand.QueryFields.ToArray());
innerCommand.InternalQuerys(SqlQueryField.InternalCreateFromFunction(baseCommand, "ROW_NUMBER() OVER( " + innerBuilder.ToString() + ")", "RN"));
innerCommand.PageSize = baseCommand.RecordStart + baseCommand.PageSize;
innerCommand.SqlJoins = baseCommand.SqlJoins;
innerCommand.SqlWhere = baseCommand.SqlWhere;
innerCommand.GroupByColumns = baseCommand.GroupByColumns;
innerCommand.SqlHaving = baseCommand.SqlHaving;
sb.AppendSelectFrom(innerCommand.GetCommandText("T"), true);
sb.AppendWhere(SqlCondition.GreaterThanColumn(baseCommand, "RN", baseCommand.RecordStart.ToString()));
}
else//正常模式
{
if (baseCommand.PageSize > 0)
{
sb.AppendSelectTop(baseCommand.PageSize);
}
sb.AppendSelectDistinct(baseCommand.UseDistinct).AppendAllColumnNames(baseCommand.QueryFields);
sb.AppendSelectFromAndJoins(baseCommand.TableName, baseCommand.IsFromSql, baseCommand.SqlJoins);
sb.AppendWhere(baseCommand.SqlWhere);
sb.AppendSelectGroupBys(baseCommand.GroupByColumns);
sb.AppendHaving(baseCommand.SqlHaving);
sb.AppendSelectOrderBys(baseCommand.SqlOrders, orderReverse);
}
return sb.ToString();
}
示例3: InternalGetPagerCommand
/// <summary>
/// 获取选择语句内容
/// </summary>
/// <param name="baseCommand">源选择语句</param>
/// <param name="recordCount">记录数量</param>
/// <param name="orderReverse">是否反转排序</param>
/// <returns>选择语句内容</returns>
internal static String InternalGetPagerCommand(SelectCommand baseCommand, Int32 recordCount, Boolean orderReverse)
{
SqlCommandBuilder sb = new SqlCommandBuilder(baseCommand.Database);
sb.AppendSelectPrefix();
if (baseCommand.PageSize > 0 && baseCommand.RecordStart > 0)//分页模式
{
Int32 realPageCount = (recordCount + baseCommand.PageSize - 1) / baseCommand.PageSize;
Int32 realPageIndex = (baseCommand.RecordStart / baseCommand.PageSize) + 1;
if (realPageIndex >= realPageCount)//最后一页
{
sb.AppendSelectDistinct(baseCommand.UseDistinct).AppendAllColumnNames(baseCommand.QueryFields);
SelectCommand innerCommand = new SelectCommand(baseCommand.Database, baseCommand.TableName);
innerCommand.QueryFields = baseCommand.QueryFields;
innerCommand.PageSize = recordCount - baseCommand.RecordStart;
innerCommand.SqlJoins = baseCommand.SqlJoins;
innerCommand.SqlWhere = baseCommand.SqlWhere;
innerCommand.GroupByColumns = baseCommand.GroupByColumns;
innerCommand.SqlHaving = baseCommand.SqlHaving;
innerCommand.SqlOrders = baseCommand.SqlOrders;
sb.AppendSelectFrom(innerCommand.GetCommandText("T", !orderReverse), true);
sb.AppendSelectOrderBys(baseCommand.SqlOrders, orderReverse);
}
else if (realPageIndex < (realPageCount / 2 + realPageCount % 2))//前1/2部分页
{
/*
SELECT * FROM
(
SELECT TOP 10 * FROM
(
SELECT TOP 30 *
FROM TABLE_NAME
ORDER BY ID ASC
) AS T1
ORDER BY ID DESC
) AS T2
ORDER BY ID ASC
*/
sb.AppendSelectDistinct(baseCommand.UseDistinct).AppendAllColumnNames(baseCommand.QueryFields);
SelectCommand innestCommand = new SelectCommand(baseCommand.Database, baseCommand.TableName);
innestCommand.QueryFields = baseCommand.QueryFields;
innestCommand.PageSize = baseCommand.RecordStart + baseCommand.PageSize;
innestCommand.SqlJoins = baseCommand.SqlJoins;
innestCommand.SqlWhere = baseCommand.SqlWhere;
innestCommand.GroupByColumns = baseCommand.GroupByColumns;
innestCommand.SqlHaving = baseCommand.SqlHaving;
innestCommand.SqlOrders = baseCommand.SqlOrders;
SelectCommand innerCommand = new SelectCommand(baseCommand.Database, innestCommand, "T1");
innerCommand.QueryFields = baseCommand.QueryFields;
innerCommand.PageSize = baseCommand.PageSize;
innerCommand.SqlOrders = baseCommand.SqlOrders;
sb.AppendSelectFrom(innerCommand.GetCommandText("T2", !orderReverse), true);
sb.AppendSelectOrderBys(baseCommand.SqlOrders, orderReverse);
}
else//后1/2部分页
{
sb.AppendSelectTop(baseCommand.PageSize);
sb.AppendSelectDistinct(baseCommand.UseDistinct).AppendAllColumnNames(baseCommand.QueryFields);
SelectCommand innerCommand = new SelectCommand(baseCommand.Database, baseCommand.TableName);
innerCommand.QueryFields = baseCommand.QueryFields;
innerCommand.PageSize = recordCount - baseCommand.RecordStart;
innerCommand.SqlJoins = baseCommand.SqlJoins;
innerCommand.SqlWhere = baseCommand.SqlWhere;
innerCommand.GroupByColumns = baseCommand.GroupByColumns;
innerCommand.SqlHaving = baseCommand.SqlHaving;
innerCommand.SqlOrders = baseCommand.SqlOrders;
sb.AppendSelectFrom(innerCommand.GetCommandText("T", !orderReverse), true);
sb.AppendSelectOrderBys(baseCommand.SqlOrders, orderReverse);
}
}
else//正常模式
{
if (baseCommand.PageSize > 0)
{
sb.AppendSelectTop(baseCommand.PageSize);
}
sb.AppendSelectDistinct(baseCommand.UseDistinct).AppendAllColumnNames(baseCommand.QueryFields);
sb.AppendSelectFromAndJoins(baseCommand.TableName, baseCommand.IsFromSql, baseCommand.SqlJoins);
sb.AppendWhere(baseCommand.SqlWhere);
sb.AppendSelectGroupBys(baseCommand.GroupByColumns);
sb.AppendHaving(baseCommand.SqlHaving);
sb.AppendSelectOrderBys(baseCommand.SqlOrders, orderReverse);
//.........这里部分代码省略.........