コード例 #1
0
        /// <summary>
        /// 获取选择语句内容
        /// </summary>
        /// <param name="cmd">选择语句类</param>
        /// <param name="realPageIndex">实际页索引</param>
        /// <param name="realPageCount">实际页数量</param>
        /// <param name="orderReverse">是否反转排序</param>
        /// <returns>选择语句内容</returns>
        internal static String InternalGetSelectCommand(SelectCommand cmd, Int32 realPageIndex, Int32 realPageCount, Boolean orderReverse)
        {
            SqlCommandBuilder sb = new SqlCommandBuilder(cmd.DatabaseType);

            sb.AppendSelectPrefix();

            sb.AppendSelectDistinct(cmd.UseDistinct).AppendAllColumnNames(cmd.QueryFields);
            sb.AppendSelectFromAndJoins(cmd.TableName, cmd.IsFromSql, cmd.SqlJoins);

            sb.AppendWhere(cmd.SqlWhere);
            sb.AppendSelectGroupBys(cmd.GroupByColumns);
            sb.AppendHaving(cmd.SqlHaving);
            sb.AppendSelectOrderBys(cmd.SqlOrders, orderReverse);

            if (cmd.PageSize > 0 && cmd.PageIndex == 1)
            {
                sb.AppendSelectLimit(cmd.PageSize);
            }
            else if (cmd.PageSize > 0 && cmd.PageIndex > 1)
            {
                sb.AppendSelectLimit(cmd.PageSize * (realPageIndex - 1), cmd.PageSize);
            }

            return(sb.ToString());
        }
コード例 #2
0
        /// <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.UseDistinct, baseCommand.InternalGetQueryFieldList());
            sb.AppendSelectFromAndJoins(baseCommand.TableName, baseCommand.IsFromSql, baseCommand.InternalGetJoinList());

            sb.AppendWhere(baseCommand.WhereCondition);
            sb.AppendSelectGroupBys(baseCommand.InternalGetGroupByFieldList());
            sb.AppendHaving(baseCommand.InternalGetHavingCondition());
            sb.AppendSelectOrderBys(baseCommand.InternalGetOrderList(), orderReverse);

            if (baseCommand.PageSize > 0 && baseCommand.RecordStart <= 0)
            {
                sb.AppendSelectLimit(baseCommand.PageSize);
            }
            else if (baseCommand.PageSize > 0 && baseCommand.RecordStart > 0)
            {
                sb.AppendSelectLimit(baseCommand.RecordStart, baseCommand.PageSize);
            }

            return(sb.ToString());
        }
コード例 #3
0
        /// <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.UseDistinct, baseCommand.InternalGetQueryFieldList());

            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 = baseCommand.Database.InternalCreateSelectCommand(baseCommand, baseCommand.TableName);
                innestCommand.InternalSetQueryFieldList(baseCommand);
                innestCommand.InternalSetJoinList(baseCommand);
                innestCommand.InternalSetWhereCondition(baseCommand);
                innestCommand.InternalSetGroupByFieldList(baseCommand);
                innestCommand.InternalSetHavingCondition(baseCommand);
                innestCommand.InternalSetOrderList(baseCommand);

                SelectCommand innerCommand = baseCommand.Database.InternalCreateSelectCommand(baseCommand, innestCommand, "");
                innerCommand.InternalSetWhereCondition(innerCommand.ConditionBuilder.LessThanOrEqualColumn("ROWNUM", (baseCommand.RecordStart + baseCommand.PageSize).ToString()));
                innerCommand.InternalQuerys(baseCommand.QueryFields);
                innerCommand.InternalQuerys(SqlQueryField.InternalCreateFromFunction(baseCommand, "ROWNUM", "RN"));

                sb.AppendSelectFrom(innerCommand.GetCommandText(), true);
                sb.AppendWhere(baseCommand.ConditionBuilder.GreaterThanColumn("RN", baseCommand.RecordStart.ToString()));
            }
            else//正常模式
            {
                sb.AppendSelectFromAndJoins(baseCommand.TableName, baseCommand.IsFromSql, baseCommand.InternalGetJoinList());

                ISqlCondition where = baseCommand.WhereCondition;

                if (baseCommand.PageSize > 0)
                {
                    where = baseCommand.ConditionBuilder.And(where, baseCommand.ConditionBuilder.LessThanOrEqualColumn("ROWNUM", baseCommand.PageSize.ToString()));
                }

                sb.AppendWhere(where);
                sb.AppendSelectGroupBys(baseCommand.InternalGetGroupByFieldList());
                sb.AppendHaving(baseCommand.InternalGetHavingCondition());
                sb.AppendSelectOrderBys(baseCommand.InternalGetOrderList(), orderReverse);
            }

            return(sb.ToString());
        }
コード例 #4
0
        /// <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();
        }
コード例 #5
0
        /// <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.UseDistinct, baseCommand.InternalGetQueryFieldList());

                SqlCommandBuilder innerBuilder = new SqlCommandBuilder(baseCommand.Database);
                innerBuilder.AppendSelectOrderBys(baseCommand.InternalGetOrderList(), false);

                SelectCommand innerCommand = baseCommand.Database.InternalCreateSelectCommand(baseCommand, baseCommand.TableName);
                innerCommand.InternalQuerys(baseCommand.QueryFields);
                innerCommand.InternalQuerys(SqlQueryField.InternalCreateFromFunction(baseCommand, "ROW_NUMBER() OVER( " + innerBuilder.ToString() + ")", "RN"));
                innerCommand.PageSize = baseCommand.RecordStart + baseCommand.PageSize;
                innerCommand.InternalSetJoinList(baseCommand);
                innerCommand.InternalSetWhereCondition(baseCommand);
                innerCommand.InternalSetGroupByFieldList(baseCommand);
                innerCommand.InternalSetHavingCondition(baseCommand);

                sb.AppendSelectFrom(innerCommand.GetCommandText("T"), true);
                sb.AppendWhere(baseCommand.ConditionBuilder.GreaterThanColumn("RN", baseCommand.RecordStart.ToString()));
            }
            else//正常模式
            {
                if (baseCommand.PageSize > 0)
                {
                    sb.AppendSelectTop(baseCommand.PageSize);
                }

                sb.AppendSelectDistinct(baseCommand.UseDistinct).AppendAllColumnNames(baseCommand.UseDistinct, baseCommand.InternalGetQueryFieldList());
                sb.AppendSelectFromAndJoins(baseCommand.TableName, baseCommand.IsFromSql, baseCommand.InternalGetJoinList());

                sb.AppendWhere(baseCommand.WhereCondition);
                sb.AppendSelectGroupBys(baseCommand.InternalGetGroupByFieldList());
                sb.AppendHaving(baseCommand.InternalGetHavingCondition());
                sb.AppendSelectOrderBys(baseCommand.InternalGetOrderList(), orderReverse);
            }

            return(sb.ToString());
        }
コード例 #6
0
        /// <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();
        }
コード例 #7
0
        /// <summary>
        /// 获取选择语句内容
        /// </summary>
        /// <param name="cmd">选择语句类</param>
        /// <param name="realPageIndex">实际页索引</param>
        /// <param name="realPageCount">实际页数量</param>
        /// <param name="orderReverse">是否反转排序</param>
        /// <returns>选择语句内容</returns>
        internal static String InternalGetSelectCommand(SelectCommand cmd, Int32 realPageIndex, Int32 realPageCount, Boolean orderReverse)
        {
            SqlCommandBuilder sb = new SqlCommandBuilder(cmd.DatabaseType);

            sb.AppendSelectPrefix();
            sb.AppendSelectDistinct(cmd.UseDistinct).AppendAllColumnNames(cmd.QueryFields);

            if (cmd.PageSize == 0)//正常模式
            {
                sb.AppendSelectFromAndJoins(cmd.TableName, cmd.IsFromSql, cmd.SqlJoins);

                sb.AppendWhere(cmd.SqlWhere);
                sb.AppendSelectGroupBys(cmd.GroupByColumns);
                sb.AppendHaving(cmd.SqlHaving);
                sb.AppendSelectOrderBys(cmd.SqlOrders, orderReverse);
            }
            else//分页模式
            {
                /*
                 *  SELECT * FROM
                 *  (
                 *      SELECT A.*, ROWNUM RN
                 *      FROM (SELECT * FROM TABLE_NAME) A
                 *      WHERE ROWNUM <= 40
                 *  )
                 *  WHERE RN >= 21
                 */
                SelectCommand innestCommand = new SelectCommand(cmd.Database, cmd.TableName);
                innestCommand.QueryFields    = cmd.QueryFields;
                innestCommand.SqlJoins       = cmd.SqlJoins;
                innestCommand.SqlWhere       = cmd.SqlWhere;
                innestCommand.GroupByColumns = cmd.GroupByColumns;
                innestCommand.SqlHaving      = cmd.SqlHaving;
                innestCommand.SqlOrders      = cmd.SqlOrders;

                SelectCommand innerCommand = new SelectCommand(cmd.Database, innestCommand, "T");
                innerCommand.SqlWhere = SqlCondition.LessThanOrEqual("ROWNUM", realPageIndex * cmd.PageSize);
                innerCommand.InternalQuerys(cmd.QueryFields.ToArray());
                innerCommand.InternalQuerys(SqlQueryField.InternalCreateFromFunction("ROWNUM", "RN"));

                sb.AppendSelectFrom(innerCommand.ToString("T"), true);
                sb.AppendWhere(SqlCondition.GreaterThanOrEqual("RN", (realPageIndex - 1) * cmd.PageSize + 1));
            }

            return(sb.ToString());
        }
コード例 #8
0
        /// <summary>
        /// 获取选择语句内容
        /// </summary>
        /// <param name="cmd">选择语句类</param>
        /// <param name="realPageIndex">实际页索引</param>
        /// <param name="realPageCount">实际页数量</param>
        /// <param name="orderReverse">是否反转排序</param>
        /// <returns>选择语句内容</returns>
        internal static String InternalGetSelectCommand(SelectCommand cmd, Int32 realPageIndex, Int32 realPageCount, Boolean orderReverse)
        {
            SqlCommandBuilder sb = new SqlCommandBuilder(cmd.DatabaseType);
            sb.AppendSelectPrefix();
            sb.AppendSelectDistinct(cmd.UseDistinct).AppendAllColumnNames(cmd.QueryFields);

            if (cmd.PageSize == 0)//正常模式
            {
                sb.AppendSelectFromAndJoins(cmd.TableName, cmd.IsFromSql, cmd.SqlJoins);

                sb.AppendWhere(cmd.SqlWhere);
                sb.AppendSelectGroupBys(cmd.GroupByColumns);
                sb.AppendHaving(cmd.SqlHaving);
                sb.AppendSelectOrderBys(cmd.SqlOrders, orderReverse);
            }
            else//分页模式
            {
                /*
                    SELECT * FROM
                    (
                        SELECT A.*, ROWNUM RN
                        FROM (SELECT * FROM TABLE_NAME) A
                        WHERE ROWNUM <= 40
                    )
                    WHERE RN >= 21 
                */
                SelectCommand innestCommand = new SelectCommand(cmd.Database, cmd.TableName);
                innestCommand.QueryFields = cmd.QueryFields;
                innestCommand.SqlJoins = cmd.SqlJoins;
                innestCommand.SqlWhere = cmd.SqlWhere;
                innestCommand.GroupByColumns = cmd.GroupByColumns;
                innestCommand.SqlHaving = cmd.SqlHaving;
                innestCommand.SqlOrders = cmd.SqlOrders;
                
                SelectCommand innerCommand = new SelectCommand(cmd.Database, innestCommand, "T");
                innerCommand.SqlWhere = SqlCondition.LessThanOrEqual("ROWNUM", realPageIndex * cmd.PageSize);
                innerCommand.InternalQuerys(cmd.QueryFields.ToArray());
                innerCommand.InternalQuerys(SqlQueryField.InternalCreateFromFunction("ROWNUM", "RN"));
                
                sb.AppendSelectFrom(innerCommand.ToString("T"), true);
                sb.AppendWhere(SqlCondition.GreaterThanOrEqual("RN", (realPageIndex - 1) * cmd.PageSize + 1));
            }

            return sb.ToString();
        }
コード例 #9
0
        /// <summary>
        /// 获取选择数量语句
        /// </summary>
        /// <param name="baseCommand">源选择语句</param>
        /// <returns>选择数量语句</returns>
        internal static String InternalGetCountCommand(SelectCommand baseCommand)
        {
            SqlCommandBuilder sb = new SqlCommandBuilder(baseCommand.Database);

            List <SqlQueryField> queryFields = new List <SqlQueryField>();

            queryFields.Add(SqlQueryField.InternalCreateFromAggregateFunction(baseCommand, SqlAggregateFunction.Count));

            sb.AppendSelectPrefix();
            sb.AppendSelectDistinct(baseCommand.UseDistinct).AppendAllColumnNames(baseCommand.UseDistinct, queryFields);
            sb.AppendSelectFromAndJoins(baseCommand.TableName, baseCommand.IsFromSql, baseCommand.InternalGetJoinList());

            sb.AppendWhere(baseCommand.WhereCondition);
            sb.AppendSelectGroupBys(baseCommand.InternalGetGroupByFieldList());
            sb.AppendHaving(baseCommand.InternalGetHavingCondition());

            return(sb.ToString());
        }
コード例 #10
0
        /// <summary>
        /// 获取选择空内容语句
        /// </summary>
        /// <param name="baseCommand">源选择语句</param>
        /// <param name="orderReverse">是否反转排序</param>
        /// <returns>选择空内容语句</returns>
        internal static String InternalGetSelectNoneCommand(SelectCommand baseCommand, Boolean orderReverse)
        {
            SqlCommandBuilder sb = new SqlCommandBuilder(baseCommand.Database);

            sb.AppendSelectPrefix();
            sb.AppendSelectDistinct(baseCommand.UseDistinct).AppendAllColumnNames(baseCommand.UseDistinct, baseCommand.InternalGetQueryFieldList());
            sb.AppendSelectFromAndJoins(baseCommand.TableName, baseCommand.IsFromSql, baseCommand.InternalGetJoinList());

            if (baseCommand.WhereCondition != null)
            {
                sb.AppendWhere(baseCommand.ConditionBuilder.And(baseCommand.ConditionBuilder.False(), baseCommand.WhereCondition));
            }
            else
            {
                sb.AppendWhere(baseCommand.ConditionBuilder.False());
            }

            sb.AppendSelectGroupBys(baseCommand.InternalGetGroupByFieldList());
            sb.AppendHaving(baseCommand.InternalGetHavingCondition());
            sb.AppendSelectOrderBys(baseCommand.InternalGetOrderList(), orderReverse);

            return(sb.ToString());
        }
コード例 #11
0
        /// <summary>
        /// 获取选择语句内容
        /// </summary>
        /// <param name="cmd">选择语句类</param>
        /// <param name="realPageIndex">实际页索引</param>
        /// <param name="realPageCount">实际页数量</param>
        /// <param name="orderReverse">是否反转排序</param>
        /// <returns>选择语句内容</returns>
        internal static String InternalGetSelectCommand(SelectCommand cmd, Int32 realPageIndex, Int32 realPageCount, Boolean orderReverse)
        {
            SqlCommandBuilder sb = new SqlCommandBuilder(cmd.DatabaseType);
            sb.AppendSelectPrefix();
            
            sb.AppendSelectDistinct(cmd.UseDistinct).AppendAllColumnNames(cmd.QueryFields);
            sb.AppendSelectFromAndJoins(cmd.TableName, cmd.IsFromSql, cmd.SqlJoins);

            sb.AppendWhere(cmd.SqlWhere);
            sb.AppendSelectGroupBys(cmd.GroupByColumns);
            sb.AppendHaving(cmd.SqlHaving);
            sb.AppendSelectOrderBys(cmd.SqlOrders, orderReverse);

            if (cmd.PageSize > 0 && cmd.PageIndex == 1)
            {
                sb.AppendSelectLimit(cmd.PageSize);
            }
            else if (cmd.PageSize > 0 && cmd.PageIndex > 1)
            {
                sb.AppendSelectLimit(cmd.PageSize * (realPageIndex - 1), cmd.PageSize);
            }

            return sb.ToString();
        }
コード例 #12
0
        /// <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);
            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);

            if (baseCommand.PageSize > 0 && baseCommand.RecordStart <= 0)
            {
                sb.AppendSelectLimit(baseCommand.PageSize);
            }
            else if (baseCommand.PageSize > 0 && baseCommand.RecordStart > 0)
            {
                sb.AppendSelectLimit(baseCommand.RecordStart, baseCommand.PageSize);
            }

            return sb.ToString();
        }
コード例 #13
0
        /// <summary>
        /// 获取选择语句内容
        /// </summary>
        /// <param name="cmd">选择语句类</param>
        /// <param name="realPageIndex">实际页索引</param>
        /// <param name="realPageCount">实际页数量</param>
        /// <param name="orderReverse">是否反转排序</param>
        /// <returns>选择语句内容</returns>
        internal static String InternalGetSelectCommand(SelectCommand cmd, Int32 realPageIndex, Int32 realPageCount, Boolean orderReverse)
        {
            SqlCommandBuilder sb = new SqlCommandBuilder(cmd.DatabaseType);

            sb.AppendSelectPrefix();

            if (realPageIndex == 1)//第一页
            {
                if (cmd.PageSize > 0)
                {
                    sb.AppendSelectTop(cmd.PageSize);
                }

                sb.AppendSelectDistinct(cmd.UseDistinct).AppendAllColumnNames(cmd.QueryFields);
                sb.AppendSelectFromAndJoins(cmd.TableName, cmd.IsFromSql, cmd.SqlJoins);

                sb.AppendWhere(cmd.SqlWhere);
                sb.AppendSelectGroupBys(cmd.GroupByColumns);
                sb.AppendHaving(cmd.SqlHaving);
                sb.AppendSelectOrderBys(cmd.SqlOrders, orderReverse);
            }
            else if (realPageIndex == realPageCount)//最后一页
            {
                sb.AppendSelectDistinct(cmd.UseDistinct).AppendAllColumnNames(cmd.QueryFields);

                SelectCommand innerCommand = new SelectCommand(cmd.Database, cmd.TableName);
                innerCommand.QueryFields    = cmd.QueryFields;
                innerCommand.PageSize       = cmd.RecordCount - cmd.PageSize * (realPageIndex - 1);
                innerCommand.SqlJoins       = cmd.SqlJoins;
                innerCommand.SqlWhere       = cmd.SqlWhere;
                innerCommand.GroupByColumns = cmd.GroupByColumns;
                innerCommand.SqlHaving      = cmd.SqlHaving;
                innerCommand.SqlOrders      = cmd.SqlOrders;

                sb.AppendSelectFrom(innerCommand.ToString("T", !orderReverse), true);
                sb.AppendSelectOrderBys(cmd.SqlOrders, orderReverse);
            }
            else if (realPageIndex < (realPageCount / 2 + realPageCount % 2))//前1/2部分页
            {
                sb.AppendSelectDistinct(cmd.UseDistinct).AppendAllColumnNames(cmd.QueryFields);

                SelectCommand innestCommand = new SelectCommand(cmd.Database, cmd.TableName);
                innestCommand.QueryFields    = cmd.QueryFields;
                innestCommand.PageSize       = cmd.PageSize * realPageIndex;
                innestCommand.SqlJoins       = cmd.SqlJoins;
                innestCommand.SqlWhere       = cmd.SqlWhere;
                innestCommand.GroupByColumns = cmd.GroupByColumns;
                innestCommand.SqlHaving      = cmd.SqlHaving;
                innestCommand.SqlOrders      = cmd.SqlOrders;

                SelectCommand innerCommand = new SelectCommand(cmd.Database, innestCommand, "T");
                innerCommand.QueryFields = cmd.QueryFields;
                innerCommand.PageSize    = cmd.PageSize;
                innerCommand.SqlOrders   = cmd.SqlOrders;

                sb.AppendSelectFrom(innerCommand.ToString("T", !orderReverse), true);
                sb.AppendSelectOrderBys(cmd.SqlOrders, orderReverse);
            }
            else//后1/2部分页
            {
                sb.AppendSelectTop(cmd.PageSize);
                sb.AppendSelectDistinct(cmd.UseDistinct).AppendAllColumnNames(cmd.QueryFields);

                SelectCommand innerCommand = new SelectCommand(cmd.Database, cmd.TableName);
                innerCommand.QueryFields    = cmd.QueryFields;
                innerCommand.PageSize       = cmd.RecordCount - cmd.PageSize * (realPageIndex - 1);
                innerCommand.SqlJoins       = cmd.SqlJoins;
                innerCommand.SqlWhere       = cmd.SqlWhere;
                innerCommand.GroupByColumns = cmd.GroupByColumns;
                innerCommand.SqlHaving      = cmd.SqlHaving;
                innerCommand.SqlOrders      = cmd.SqlOrders;

                sb.AppendSelectFrom(innerCommand.ToString("T", !orderReverse), true);
                sb.AppendSelectOrderBys(cmd.SqlOrders, orderReverse);
            }

            return(sb.ToString());
        }
コード例 #14
0
        /// <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.UseDistinct, baseCommand.InternalGetQueryFieldList());

                    SelectCommand innerCommand = baseCommand.Database.InternalCreateSelectCommand(baseCommand, baseCommand.TableName);
                    innerCommand.PageSize = recordCount - baseCommand.RecordStart;
                    innerCommand.InternalSetQueryFieldList(baseCommand);
                    innerCommand.InternalSetJoinList(baseCommand);
                    innerCommand.InternalSetWhereCondition(baseCommand);
                    innerCommand.InternalSetGroupByFieldList(baseCommand);
                    innerCommand.InternalSetHavingCondition(baseCommand);
                    innerCommand.InternalSetOrderList(baseCommand);

                    sb.AppendSelectFrom(innerCommand.GetCommandText("T", !orderReverse), true);
                    sb.AppendSelectOrderBys(baseCommand.InternalGetOrderList(), 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.UseDistinct, baseCommand.InternalGetQueryFieldList());

                    SelectCommand innestCommand = baseCommand.Database.InternalCreateSelectCommand(baseCommand, baseCommand.TableName);
                    innestCommand.PageSize = baseCommand.RecordStart + baseCommand.PageSize;
                    innestCommand.InternalSetQueryFieldList(baseCommand);
                    innestCommand.InternalSetJoinList(baseCommand);
                    innestCommand.InternalSetWhereCondition(baseCommand);
                    innestCommand.InternalSetGroupByFieldList(baseCommand);
                    innestCommand.InternalSetHavingCondition(baseCommand);
                    innestCommand.InternalSetOrderList(baseCommand);

                    SelectCommand innerCommand = baseCommand.Database.InternalCreateSelectCommand(baseCommand, innestCommand, "T1");
                    innerCommand.PageSize = baseCommand.PageSize;
                    innerCommand.InternalSetQueryFieldList(baseCommand);
                    innerCommand.InternalSetOrderList(baseCommand);

                    sb.AppendSelectFrom(innerCommand.GetCommandText("T2", !orderReverse), true);
                    sb.AppendSelectOrderBys(baseCommand.InternalGetOrderList(), orderReverse);
                }
                else//后1/2部分页
                {
                    sb.AppendSelectTop(baseCommand.PageSize);
                    sb.AppendSelectDistinct(baseCommand.UseDistinct).AppendAllColumnNames(baseCommand.UseDistinct, baseCommand.InternalGetQueryFieldList());

                    SelectCommand innerCommand = baseCommand.Database.InternalCreateSelectCommand(baseCommand, baseCommand.TableName);
                    innerCommand.PageSize = recordCount - baseCommand.RecordStart;
                    innerCommand.InternalSetQueryFieldList(baseCommand);
                    innerCommand.InternalSetJoinList(baseCommand);
                    innerCommand.InternalSetWhereCondition(baseCommand);
                    innerCommand.InternalSetGroupByFieldList(baseCommand);
                    innerCommand.InternalSetHavingCondition(baseCommand);
                    innerCommand.InternalSetOrderList(baseCommand);

                    sb.AppendSelectFrom(innerCommand.GetCommandText("T", !orderReverse), true);
                    sb.AppendSelectOrderBys(baseCommand.InternalGetOrderList(), orderReverse);
                }
            }
            else//正常模式
            {
                if (baseCommand.PageSize > 0)
                {
                    sb.AppendSelectTop(baseCommand.PageSize);
                }

                sb.AppendSelectDistinct(baseCommand.UseDistinct).AppendAllColumnNames(baseCommand.UseDistinct, baseCommand.InternalGetQueryFieldList());
                sb.AppendSelectFromAndJoins(baseCommand.TableName, baseCommand.IsFromSql, baseCommand.InternalGetJoinList());

                sb.AppendWhere(baseCommand.WhereCondition);
                sb.AppendSelectGroupBys(baseCommand.InternalGetGroupByFieldList());
                sb.AppendHaving(baseCommand.InternalGetHavingCondition());
                sb.AppendSelectOrderBys(baseCommand.InternalGetOrderList(), orderReverse);
            }

            return(sb.ToString());
        }
コード例 #15
0
        /// <summary>
        /// 获取选择空内容语句
        /// </summary>
        /// <param name="baseCommand">源选择语句</param>
        /// <param name="orderReverse">是否反转排序</param>
        /// <returns>选择空内容语句</returns>
        internal static String InternalGetSelectNoneCommand(SelectCommand baseCommand, Boolean orderReverse)
        {
            SqlCommandBuilder sb = new SqlCommandBuilder(baseCommand.Database);

            sb.AppendSelectPrefix();
            sb.AppendSelectDistinct(baseCommand.UseDistinct).AppendAllColumnNames(baseCommand.UseDistinct, baseCommand.InternalGetQueryFieldList());
            sb.AppendSelectFromAndJoins(baseCommand.TableName, baseCommand.IsFromSql, baseCommand.InternalGetJoinList());

            if (baseCommand.WhereCondition != null)
            {
                sb.AppendWhere(baseCommand.ConditionBuilder.And(baseCommand.ConditionBuilder.False(), baseCommand.WhereCondition));
            }
            else
            {
                sb.AppendWhere(baseCommand.ConditionBuilder.False());
            }

            sb.AppendSelectGroupBys(baseCommand.InternalGetGroupByFieldList());
            sb.AppendHaving(baseCommand.InternalGetHavingCondition());
            sb.AppendSelectOrderBys(baseCommand.InternalGetOrderList(), orderReverse);

            return sb.ToString();
        }
コード例 #16
0
        /// <summary>
        /// 获取选择空内容语句
        /// </summary>
        /// <param name="baseCommand">源选择语句</param>
        /// <param name="orderReverse">是否反转排序</param>
        /// <returns>选择空内容语句</returns>
        internal static String InternalGetSelectNoneCommand(SelectCommand baseCommand, Boolean orderReverse)
        {
            SqlCommandBuilder sb = new SqlCommandBuilder(baseCommand.Database);

            sb.AppendSelectPrefix();
            sb.AppendSelectDistinct(baseCommand.UseDistinct).AppendAllColumnNames(baseCommand.QueryFields);
            sb.AppendSelectFromAndJoins(baseCommand.TableName, baseCommand.IsFromSql, baseCommand.SqlJoins);

            if (baseCommand.SqlWhere != null)
            {
                sb.AppendWhere(SqlCondition.And(baseCommand, SqlCondition.False(baseCommand), baseCommand.SqlWhere));
            }
            else
            {
                sb.AppendWhere(SqlCondition.False(baseCommand));
            }
            
            sb.AppendSelectGroupBys(baseCommand.GroupByColumns);
            sb.AppendHaving(baseCommand.SqlHaving);
            sb.AppendSelectOrderBys(baseCommand.SqlOrders, orderReverse);

            return sb.ToString();
        }
コード例 #17
0
        /// <summary>
        /// 获取选择数量语句
        /// </summary>
        /// <param name="baseCommand">源选择语句</param>
        /// <returns>选择数量语句</returns>
        internal static String InternalGetCountCommand(SelectCommand baseCommand)
        {
            SqlCommandBuilder sb = new SqlCommandBuilder(baseCommand.Database);

            List<SqlQueryField> queryFields = new List<SqlQueryField>();
            queryFields.Add(SqlQueryField.InternalCreateFromAggregateFunction(baseCommand, SqlAggregateFunction.Count));

            sb.AppendSelectPrefix();
            sb.AppendSelectDistinct(baseCommand.UseDistinct).AppendAllColumnNames(queryFields);
            sb.AppendSelectFromAndJoins(baseCommand.TableName, baseCommand.IsFromSql, baseCommand.SqlJoins);

            sb.AppendWhere(baseCommand.SqlWhere);
            sb.AppendSelectGroupBys(baseCommand.GroupByColumns);
            sb.AppendHaving(baseCommand.SqlHaving);

            return sb.ToString();
        }
コード例 #18
0
        /// <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);
            }

            return sb.ToString();
        }
コード例 #19
0
        /// <summary>
        /// 获取选择语句内容
        /// </summary>
        /// <param name="cmd">选择语句类</param>
        /// <param name="realPageIndex">实际页索引</param>
        /// <param name="realPageCount">实际页数量</param>
        /// <param name="orderReverse">是否反转排序</param>
        /// <returns>选择语句内容</returns>
        internal static String InternalGetSelectCommand(SelectCommand cmd, Int32 realPageIndex, Int32 realPageCount, Boolean orderReverse)
        {
            SqlCommandBuilder sb = new SqlCommandBuilder(cmd.DatabaseType);
            sb.AppendSelectPrefix();

            if (realPageIndex == 1)//第一页
            {
                if (cmd.PageSize > 0)
                {
                    sb.AppendSelectTop(cmd.PageSize);
                }

                sb.AppendSelectDistinct(cmd.UseDistinct).AppendAllColumnNames(cmd.QueryFields);
                sb.AppendSelectFromAndJoins(cmd.TableName, cmd.IsFromSql, cmd.SqlJoins);

                sb.AppendWhere(cmd.SqlWhere);
                sb.AppendSelectGroupBys(cmd.GroupByColumns);
                sb.AppendHaving(cmd.SqlHaving);
                sb.AppendSelectOrderBys(cmd.SqlOrders, orderReverse);
            }
            else if (realPageIndex == realPageCount)//最后一页
            {
                sb.AppendSelectDistinct(cmd.UseDistinct).AppendAllColumnNames(cmd.QueryFields);

                SelectCommand innerCommand = new SelectCommand(cmd.Database, cmd.TableName);
                innerCommand.QueryFields = cmd.QueryFields;
                innerCommand.PageSize = cmd.RecordCount - cmd.PageSize * (realPageIndex - 1);
                innerCommand.SqlJoins = cmd.SqlJoins;
                innerCommand.SqlWhere = cmd.SqlWhere;
                innerCommand.GroupByColumns = cmd.GroupByColumns;
                innerCommand.SqlHaving = cmd.SqlHaving;
                innerCommand.SqlOrders = cmd.SqlOrders;

                sb.AppendSelectFrom(innerCommand.ToString("T", !orderReverse), true);
                sb.AppendSelectOrderBys(cmd.SqlOrders, orderReverse);
            }
            else if (realPageIndex < (realPageCount / 2 + realPageCount % 2))//前1/2部分页
            {
                sb.AppendSelectDistinct(cmd.UseDistinct).AppendAllColumnNames(cmd.QueryFields);

                SelectCommand innestCommand = new SelectCommand(cmd.Database, cmd.TableName);
                innestCommand.QueryFields = cmd.QueryFields;
                innestCommand.PageSize = cmd.PageSize * realPageIndex;
                innestCommand.SqlJoins = cmd.SqlJoins;
                innestCommand.SqlWhere = cmd.SqlWhere;
                innestCommand.GroupByColumns = cmd.GroupByColumns;
                innestCommand.SqlHaving = cmd.SqlHaving;
                innestCommand.SqlOrders = cmd.SqlOrders;

                SelectCommand innerCommand = new SelectCommand(cmd.Database, innestCommand, "T");
                innerCommand.QueryFields = cmd.QueryFields;
                innerCommand.PageSize = cmd.PageSize;
                innerCommand.SqlOrders = cmd.SqlOrders;

                sb.AppendSelectFrom(innerCommand.ToString("T", !orderReverse), true);
                sb.AppendSelectOrderBys(cmd.SqlOrders, orderReverse);
            }
            else//后1/2部分页
            {
                sb.AppendSelectTop(cmd.PageSize);
                sb.AppendSelectDistinct(cmd.UseDistinct).AppendAllColumnNames(cmd.QueryFields);

                SelectCommand innerCommand = new SelectCommand(cmd.Database, cmd.TableName);
                innerCommand.QueryFields = cmd.QueryFields;
                innerCommand.PageSize = cmd.RecordCount - cmd.PageSize * (realPageIndex - 1);
                innerCommand.SqlJoins = cmd.SqlJoins;
                innerCommand.SqlWhere = cmd.SqlWhere;
                innerCommand.GroupByColumns = cmd.GroupByColumns;
                innerCommand.SqlHaving = cmd.SqlHaving;
                innerCommand.SqlOrders = cmd.SqlOrders;

                sb.AppendSelectFrom(innerCommand.ToString("T", !orderReverse), true);
                sb.AppendSelectOrderBys(cmd.SqlOrders, orderReverse);
            }

            return sb.ToString();
        }