コード例 #1
0
        public override string GetSQLString(ISQL.DBType type)
        {
            if (!StringUtil.IsNullOrEmpty(this.sql))
            {
                return(this.sql);
            }
            string field = fields.Size() == 0 ? "*" : fields.GetSQLString(type);
            string sql   = string.Empty;

            if (type == ISQL.DBType.mysql || limit == null || (limit.GetCount() == 0 && limit.GetStart() == 0))
            {
                sql = "select " + field + " from " + tables.GetSQLString(type) + where.GetSQLString(type) + groupBy.GetSQLString(type) + orderBy.GetSQLString(type) + limit.GetSQLString(type);
            }
            else
            {
                WhereSQL w1 = where.Clone();
                w1.AddCondition(new SQLCondition("rownum", (limit.GetStart() + limit.GetCount() + 1).ToString(), "<", true));
                WhereSQL w2 = where.Clone();
                w2.AddCondition(new SQLCondition("rownum", (limit.GetStart() + 1).ToString(), "<", true));
                sql = "SELECT * FROM ( SELECT A.*, ROWNUM RNNNNNN FROM (SELECT " + field + " FROM " + tables.GetSQLString(type) + where.GetSQLString(type) + groupBy.GetSQLString(type) + orderBy.GetSQLString(type) + ") A WHERE ROWNUM <= " + (limit.GetStart()
                                                                                                                                                                                                                                                 + limit.GetCount()) + " ) WHERE RNNNNNN >= " + (limit.GetStart() + 1);
            }
            return(SQLUtils.RemoveMultiBlank(sql.Trim()).Trim());
        }