コード例 #1
0
        public string GetSqlForSelectBuilder(SelectBuilderData data)
        {
            string text = "";

            text = "select " + data.Select;
            text = text + " from " + data.From;
            if (data.WhereSql.Length > 0)
            {
                text = text + " where " + data.WhereSql;
            }
            if (data.GroupBy.Length > 0)
            {
                text = text + " group by " + data.GroupBy;
            }
            if (data.Having.Length > 0)
            {
                text = text + " having " + data.Having;
            }
            if (data.OrderBy.Length > 0)
            {
                text = text + " order by " + data.OrderBy;
            }
            if (data.PagingItemsPerPage > 0)
            {
                object obj = text;
                text = obj + " offset " + (data.GetFromItems() - 1) + " rows";
                if (data.PagingItemsPerPage > 0)
                {
                    object obj2 = text;
                    text = obj2 + " fetch next " + data.PagingItemsPerPage + " rows only";
                }
            }
            return(text);
        }
コード例 #2
0
        public string GetSqlForSelectBuilder(SelectBuilderData data)
        {
            string text = "";

            text = "select " + data.Select;
            text = text + " from " + data.From;
            if (data.WhereSql.Length > 0)
            {
                text = text + " where " + data.WhereSql;
            }
            if (data.GroupBy.Length > 0)
            {
                text = text + " group by " + data.GroupBy;
            }
            if (data.Having.Length > 0)
            {
                text = text + " having " + data.Having;
            }
            if (data.OrderBy.Length > 0)
            {
                text = text + " order by " + data.OrderBy;
            }
            if (data.PagingItemsPerPage > 0 && data.PagingCurrentPage > 0)
            {
                text += string.Format(" limit {0}, {1}", data.GetFromItems() - 1, data.GetToItems());
            }
            return(text);
        }
コード例 #3
0
        public string GetSqlForSelectBuilder(SelectBuilderData data)
        {
            string text = "";

            text = "select " + data.Select;
            text = text + " from " + data.From;
            if (data.WhereSql.Length > 0)
            {
                text = text + " where " + data.WhereSql;
            }
            if (data.GroupBy.Length > 0)
            {
                text = text + " group by " + data.GroupBy;
            }
            if (data.Having.Length > 0)
            {
                text = text + " having " + data.Having;
            }
            if (data.OrderBy.Length > 0)
            {
                text = text + " order by " + data.OrderBy;
            }
            if (data.PagingItemsPerPage > 0)
            {
                if (data.PagingItemsPerPage > 0)
                {
                    text = text + " limit " + data.PagingItemsPerPage;
                }
                text = text + " offset " + (data.GetFromItems() - 1);
            }
            return(text);
        }
コード例 #4
0
        public string GetSqlForSelectBuilder(SelectBuilderData data)
        {
            var sql = "";

            sql  = "select " + data.Select;
            sql += " from " + data.From;
            if (data.WhereSql.Length > 0)
            {
                sql += " where " + data.WhereSql;
            }
            if (data.GroupBy.Length > 0)
            {
                sql += " group by " + data.GroupBy;
            }
            if (data.Having.Length > 0)
            {
                sql += " having " + data.Having;
            }
            if (data.OrderBy.Length > 0)
            {
                sql += " order by " + data.OrderBy;
            }
            if (data.PagingItemsPerPage > 0)
            {
                sql += " offset " + (data.GetFromItems() - 1) + " rows";
                if (data.PagingItemsPerPage > 0)
                {
                    sql += " fetch next " + data.PagingItemsPerPage + " rows only";
                }
            }

            return(sql);
        }
コード例 #5
0
ファイル: MySqlProvider.cs プロジェクト: zls3201/FluentData
        public string GetSqlForSelectBuilder(SelectBuilderData data)
        {
            var sql = "";

            sql  = "select " + data.Select;
            sql += " from " + data.From;
            if (data.WhereSql.Length > 0)
            {
                sql += " where " + data.WhereSql;
            }
            if (data.GroupBy.Length > 0)
            {
                sql += " group by " + data.GroupBy;
            }
            if (data.Having.Length > 0)
            {
                sql += " having " + data.Having;
            }
            if (data.OrderBy.Length > 0)
            {
                sql += " order by " + data.OrderBy;
            }
            if (data.PagingItemsPerPage > 0 &&
                data.PagingCurrentPage > 0)
            {
                sql += string.Format(" limit {0}, {1}", data.GetFromItems() - 1, data.PagingItemsPerPage);
            }

            return(sql);
        }
コード例 #6
0
ファイル: OracleProvider.cs プロジェクト: zls3201/FluentData
        public string GetSqlForSelectBuilder(SelectBuilderData data)
        {
            var sql = "";

            if (data.PagingItemsPerPage == 0)
            {
                sql  = "select " + data.Select;
                sql += " from " + data.From;
                if (data.WhereSql.Length > 0)
                {
                    sql += " where " + data.WhereSql;
                }
                if (data.GroupBy.Length > 0)
                {
                    sql += " group by " + data.GroupBy;
                }
                if (data.Having.Length > 0)
                {
                    sql += " having " + data.Having;
                }
                if (data.OrderBy.Length > 0)
                {
                    sql += " order by " + data.OrderBy;
                }
            }
            else if (data.PagingItemsPerPage > 0)
            {
                sql += " from " + data.From;
                if (data.WhereSql.Length > 0)
                {
                    sql += " where " + data.WhereSql;
                }
                if (data.GroupBy.Length > 0)
                {
                    sql += " group by " + data.GroupBy;
                }
                if (data.Having.Length > 0)
                {
                    sql += " having " + data.Having;
                }

                sql = string.Format(@"select * from
										(
											select {0}, 
												row_number() over (order by {1}) FLUENTDATA_ROWNUMBER
											{2}
										)
										where fluentdata_RowNumber between {3} and {4}
										order by fluentdata_RowNumber"                                        ,
                                    data.Select,
                                    data.OrderBy,
                                    sql,
                                    data.GetFromItems(),
                                    data.GetToItems());
            }

            return(sql);
        }
コード例 #7
0
        public string GetSqlForSelectBuilder(SelectBuilderData data)
        {
            var sql = "";

            if (data.HasFoundRows)
            {
                sql = "select SQL_CALC_FOUND_ROWS " + data.Select;
            }
            else
            {
                sql = "select " + data.Select;
            }
            sql += " from " + data.From;
            if (data.WhereSql.Length > 0)
            {
                sql += " where " + data.WhereSql;
            }
            if (data.GroupBy.Length > 0)
            {
                sql += " group by " + data.GroupBy;
            }
            if (data.Having.Length > 0)
            {
                sql += " having " + data.Having;
            }
            if (data.OrderBy.Length > 0)
            {
                sql += " order by " + data.OrderBy;
            }
            if (data.PagingItemsPerPage > 0 &&
                data.PagingCurrentPage > 0)
            {
                //sql += string.Format(" limit {0}, {1}", data.GetFromItems() - 1, data.GetToItems());
                sql += string.Format(" limit {0}, {1}", data.GetFromItems() - 1, data.PagingItemsPerPage);
            }
            if (data.HasFoundRows)
            {
                sql += ";SELECT FOUND_ROWS();";
            }
            return(sql);
        }
コード例 #8
0
        public string GetSqlForSelectBuilder(SelectBuilderData data)
        {
            var sql = new StringBuilder();

            if (data.PagingCurrentPage == 1)
            {
                if (data.PagingItemsPerPage == 0)
                {
                    sql.Append("select");
                }
                else
                {
                    sql.Append("select top " + data.PagingItemsPerPage.ToString());
                }
                sql.Append(" " + data.Select);
                sql.Append(" from " + data.From);
                if (data.WhereSql.Length > 0)
                {
                    sql.Append(" where " + data.WhereSql);
                }
                if (data.GroupBy.Length > 0)
                {
                    sql.Append(" group by " + data.GroupBy);
                }
                if (data.Having.Length > 0)
                {
                    sql.Append(" having " + data.Having);
                }
                if (data.OrderBy.Length > 0)
                {
                    sql.Append(" order by " + data.OrderBy);
                }
                return(sql.ToString());
            }
            else
            {
                sql.Append(" from " + data.From);
                if (data.WhereSql.Length > 0)
                {
                    sql.Append(" where " + data.WhereSql);
                }
                if (data.GroupBy.Length > 0)
                {
                    sql.Append(" group by " + data.GroupBy);
                }
                if (data.Having.Length > 0)
                {
                    sql.Append(" having " + data.Having);
                }

                var pagedSql = string.Format(@"with PagedPersons as
								(
									select top 100 percent {0}, row_number() over (order by {1}) as FLUENTDATA_ROWNUMBER
									{2}
								)
								select *
								from PagedPersons
								where fluentdata_RowNumber between {3} and {4}"                                ,
                                             data.Select,
                                             data.OrderBy,
                                             sql,
                                             data.GetFromItems(),
                                             data.GetToItems());
                return(pagedSql);
            }
        }
コード例 #9
0
        public string GetSqlForSelectBuilder(SelectBuilderData data)
        {
            var sql = new StringBuilder();

            if (data.PagingCurrentPage == 1)
            {
                if (data.PagingItemsPerPage == 0)
                {
                    sql.Append("select");
                }
                else
                {
                    sql.Append("select top " + data.PagingItemsPerPage.ToString());
                }
                sql.Append(" " + data.Select);
                sql.Append(" from " + data.From);
                if (data.WhereSql.Length > 0)
                {
                    sql.Append(" where " + data.WhereSql);
                }
                if (data.GroupBy.Length > 0)
                {
                    sql.Append(" group by " + data.GroupBy);
                }
                if (data.Having.Length > 0)
                {
                    sql.Append(" having " + data.Having);
                }
                if (data.OrderBy.Length > 0)
                {
                    sql.Append(" order by " + data.OrderBy);
                }
                return(sql.ToString());
            }
            else
            {
                sql.Append(" from " + data.From);
                if (data.WhereSql.Length > 0)
                {
                    sql.Append(" where " + data.WhereSql);
                }
                if (data.GroupBy.Length > 0)
                {
                    sql.Append(" group by " + data.GroupBy);
                }
                if (data.Having.Length > 0)
                {
                    sql.Append(" having " + data.Having);
                }

                var pagedSql = string.Format(@"with PagedPersons as
								(
									select top 100 percent {0}, row_number() over (order by {1}) as FLUENTDATA_ROWNUMBER
									{2}
								)
								select *
								from PagedPersons
								where fluentdata_RowNumber between {3} and {4}"                                ,
                                             data.Select,
                                             data.OrderBy,
                                             sql,
                                             data.GetFromItems(),
                                             data.GetToItems());
                return(pagedSql);
            }


            #region SqlServer 2012以上版本的分页(此效率更高,以上版本通用)

            //if (!string.IsNullOrWhiteSpace(data.Select))
            //{
            //    sql += "select " + data.Select;
            //}
            //if (!string.IsNullOrWhiteSpace(data.From))
            //{
            //    sql += " from " + data.From;
            //}
            //if (!string.IsNullOrWhiteSpace(data.WhereSql))
            //{
            //    sql += " where " + data.WhereSql;
            //}
            //if (!string.IsNullOrWhiteSpace(data.GroupBy))
            //{
            //    sql += " group by " + data.GroupBy;
            //}
            //if (!string.IsNullOrWhiteSpace(data.Having))
            //{
            //    sql += " having " + data.Having;
            //}
            //if (!string.IsNullOrWhiteSpace(data.OrderBy))
            //{
            //    sql += " order by " + data.OrderBy;
            //}
            //if (data.PagingItemsPerPage > 0)
            //{
            //    sql += " offset " + data.GetFormItemsRowsIndex + " rows";
            //    sql += " fetch next " + data.PagingItemsPerPage + " rows only";
            //}
            //return sql;

            #endregion
        }
コード例 #10
0
        public string GetSqlForSelectBuilder(SelectBuilderData data)
        {
            string text = "";

            if (data.PagingItemsPerPage == 0)
            {
                text = "select " + data.Select;
                text = text + " from " + data.From;
                if (data.WhereSql.Length > 0)
                {
                    text = text + " where " + data.WhereSql;
                }
                if (data.GroupBy.Length > 0)
                {
                    text = text + " group by " + data.GroupBy;
                }
                if (data.Having.Length > 0)
                {
                    text = text + " having " + data.Having;
                }
                if (data.OrderBy.Length > 0)
                {
                    text = text + " order by " + data.OrderBy;
                }
            }
            else if (data.PagingItemsPerPage > 0)
            {
                text = text + " from " + data.From;
                if (data.WhereSql.Length > 0)
                {
                    text = text + " where " + data.WhereSql;
                }
                if (data.GroupBy.Length > 0)
                {
                    text = text + " group by " + data.GroupBy;
                }
                if (data.Having.Length > 0)
                {
                    text = text + " having " + data.Having;
                }
                text = string.Format("select * from\r\n\t\t\t\t\t\t\t\t\t\t(\r\n\t\t\t\t\t\t\t\t\t\t\tselect {0}, \r\n\t\t\t\t\t\t\t\t\t\t\t\trow_number() over (order by {1}) FLUENTDATA_ROWNUMBER\r\n\t\t\t\t\t\t\t\t\t\t\t{2}\r\n\t\t\t\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t\t\t\t\twhere fluentdata_RowNumber between {3} and {4}\r\n\t\t\t\t\t\t\t\t\t\torder by fluentdata_RowNumber", data.Select, data.OrderBy, text, data.GetFromItems(), data.GetToItems());
            }
            return(text);
        }
コード例 #11
0
        public string GetSqlForSelectBuilder(SelectBuilderData data)
        {
            StringBuilder stringBuilder = new StringBuilder();

            if (data.PagingCurrentPage == 1)
            {
                if (data.PagingItemsPerPage == 0)
                {
                    stringBuilder.Append("select");
                }
                else
                {
                    stringBuilder.Append("select top " + data.PagingItemsPerPage.ToString());
                }
                stringBuilder.Append(" " + data.Select);
                stringBuilder.Append(" from " + data.From);
                if (data.WhereSql.Length > 0)
                {
                    stringBuilder.Append(" where " + data.WhereSql);
                }
                if (data.GroupBy.Length > 0)
                {
                    stringBuilder.Append(" group by " + data.GroupBy);
                }
                if (data.Having.Length > 0)
                {
                    stringBuilder.Append(" having " + data.Having);
                }
                if (data.OrderBy.Length > 0)
                {
                    stringBuilder.Append(" order by " + data.OrderBy);
                }
                return(stringBuilder.ToString());
            }
            stringBuilder.Append(" from " + data.From);
            if (data.WhereSql.Length > 0)
            {
                stringBuilder.Append(" where " + data.WhereSql);
            }
            if (data.GroupBy.Length > 0)
            {
                stringBuilder.Append(" group by " + data.GroupBy);
            }
            if (data.Having.Length > 0)
            {
                stringBuilder.Append(" having " + data.Having);
            }
            return(string.Format("with PagedPersons as\r\n\t\t\t\t\t\t\t\t(\r\n\t\t\t\t\t\t\t\t\tselect top 100 percent {0}, row_number() over (order by {1}) as FLUENTDATA_ROWNUMBER\r\n\t\t\t\t\t\t\t\t\t{2}\r\n\t\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t\t\tselect *\r\n\t\t\t\t\t\t\t\tfrom PagedPersons\r\n\t\t\t\t\t\t\t\twhere fluentdata_RowNumber between {3} and {4}", data.Select, data.OrderBy, stringBuilder, data.GetFromItems(), data.GetToItems()));
        }