Index: /branches/version-2_13-dev/data/class/api/operations/ItemSearch.php
===================================================================
--- /branches/version-2_13-dev/data/class/api/operations/ItemSearch.php	(revision 23124)
+++ /branches/version-2_13-dev/data/class/api/operations/ItemSearch.php	(revision 23378)
@@ -114,7 +114,8 @@
     protected function getProductsList($searchCondition, $disp_number, $startno, $linemax, &$objProduct)
     {
+        $objQuery =& SC_Query_Ex::getSingletonInstance();
+
         $arrOrderVal = array();
 
-        $objQuery =& SC_Query_Ex::getSingletonInstance();
         // 表示順序
         switch ($searchCondition['orderby']) {
@@ -147,19 +148,12 @@
                     $dtb_product_categories = 'dtb_product_categories';
                 }
-                $order = <<< __EOS__
-                    (
-                        SELECT
-                            T3.rank * 2147483648 + T2.rank
-                        FROM
-                            $dtb_product_categories T2
-                            JOIN dtb_category T3
-                              ON T2.category_id = T3.category_id
-                        WHERE T2.product_id = alldtl.product_id
-                        ORDER BY T3.rank DESC, T2.rank DESC
-                        LIMIT 1
-                    ) DESC
-                    ,product_id DESC
-__EOS__;
-                    $objQuery->setOrder($order);
+                $col = 'T3.rank * 2147483648 + T2.rank';
+                $from = "$dtb_product_categories T2 JOIN dtb_category T3 ON T2.category_id = T3.category_id";
+                $where = 'T2.product_id = alldtl.product_id';
+                $objQuery->setOrder('T3.rank DESC, T2.rank DESC');
+                $objQuery->setLimit(1);
+                $sub_sql = $objQuery->getSqlWithLimitOffset($col, $from, $where);
+
+                $objQuery->setOrder("($sub_sql) DESC ,product_id DESC");
                 break;
         }
Index: /branches/version-2_13-dev/data/class/db/SC_DB_DBFactory.php
===================================================================
--- /branches/version-2_13-dev/data/class/db/SC_DB_DBFactory.php	(revision 23124)
+++ /branches/version-2_13-dev/data/class/db/SC_DB_DBFactory.php	(revision 23378)
@@ -195,3 +195,24 @@
         return $objManager->listTables();
     }
+
+    /**
+     * SQL 文に OFFSET, LIMIT を付加する。
+     *
+     * @param string 元の SQL 文
+     * @param integer LIMIT
+     * @param integer OFFSET
+     * @return string 付加後の SQL 文
+     */
+    function addLimitOffset($sql, $limit = 0, $offset = 0)
+    {
+        if ($limit != 0) {
+            $sql .= " LIMIT $limit";
+        }
+        if (strlen($offset) === 0) {
+            $offset = 0;
+        }
+        $sql .= " OFFSET $offset";
+
+        return $sql;
+    }
 }
Index: /branches/version-2_13-dev/data/class/pages/admin/LC_Page_Admin_Home.php
===================================================================
--- /branches/version-2_13-dev/data/class/pages/admin/LC_Page_Admin_Home.php	(revision 23124)
+++ /branches/version-2_13-dev/data/class/pages/admin/LC_Page_Admin_Home.php	(revision 23378)
@@ -251,46 +251,30 @@
         $objQuery =& SC_Query_Ex::getSingletonInstance();
 
-        $sql = <<< __EOS__
-            SELECT
-                ord.order_id,
-                ord.customer_id,
-                ord.order_name01 AS name01,
-                ord.order_name02 AS name02,
-                ord.total,
-                ord.create_date,
-                (SELECT
-                    det.product_name
-                FROM
-                    dtb_order_detail AS det
-                WHERE
-                    ord.order_id = det.order_id
-                ORDER BY det.order_detail_id
-                LIMIT 1
-                ) AS product_name,
-                (SELECT
-                    pay.payment_method
-                FROM
-                    dtb_payment AS pay
-                WHERE
-                    ord.payment_id = pay.payment_id
-                ) AS payment_method
-            FROM (
-                SELECT
-                    order_id,
-                    customer_id,
-                    order_name01,
-                    order_name02,
-                    total,
-                    create_date,
-                    payment_id
-                FROM
-                    dtb_order AS ord
-                WHERE
-                    del_flg = 0 AND status <> ?
-                ORDER BY
-                    create_date DESC LIMIT 10 OFFSET 0
-            ) AS ord
+        $objQuery->setOrder('order_detail_id');
+        $objQuery->setLimit(1);
+        $sql_product_name = $objQuery->getSqlWithLimitOffset('product_name', 'dtb_order_detail', 'order_id = dtb_order.order_id');
+
+        $cols = <<< __EOS__
+            dtb_order.order_id,
+            dtb_order.customer_id,
+            dtb_order.order_name01 AS name01,
+            dtb_order.order_name02 AS name02,
+            dtb_order.total,
+            dtb_order.create_date,
+            ($sql_product_name) AS product_name,
+            (SELECT
+                pay.payment_method
+            FROM
+                dtb_payment AS pay
+            WHERE
+                dtb_order.payment_id = pay.payment_id
+            ) AS payment_method
 __EOS__;
-        $arrNewOrder = $objQuery->getAll($sql, ORDER_CANCEL);
+        $from = 'dtb_order';
+        $where = 'del_flg = 0 AND status <> ?';
+        $objQuery->setOrder('create_date DESC');
+        $objQuery->setLimit(10);
+        $arrNewOrder = $objQuery->select($cols, $from, $where, ORDER_CANCEL);
+
         foreach ($arrNewOrder as $key => $val) {
             $arrNewOrder[$key]['create_date'] = str_replace('-', '/', substr($val['create_date'], 0,19));
Index: /branches/version-2_13-dev/data/class/pages/products/LC_Page_Products_List.php
===================================================================
--- /branches/version-2_13-dev/data/class/pages/products/LC_Page_Products_List.php	(revision 23256)
+++ /branches/version-2_13-dev/data/class/pages/products/LC_Page_Products_List.php	(revision 23378)
@@ -213,7 +213,8 @@
     public function lfGetProductsList($searchCondition, $disp_number, $startno, &$objProduct)
     {
+        $objQuery =& SC_Query_Ex::getSingletonInstance();
+
         $arrOrderVal = array();
 
-        $objQuery =& SC_Query_Ex::getSingletonInstance();
         // 表示順序
         switch ($this->orderby) {
@@ -235,19 +236,12 @@
                     $dtb_product_categories = 'dtb_product_categories';
                 }
-                $order = <<< __EOS__
-                    (
-                        SELECT
-                            T3.rank * 2147483648 + T2.rank
-                        FROM
-                            $dtb_product_categories T2
-                            JOIN dtb_category T3
-                              ON T2.category_id = T3.category_id
-                        WHERE T2.product_id = alldtl.product_id
-                        ORDER BY T3.rank DESC, T2.rank DESC
-                        LIMIT 1
-                    ) DESC
-                    ,product_id DESC
-__EOS__;
-                $objQuery->setOrder($order);
+                $col = 'T3.rank * 2147483648 + T2.rank';
+                $from = "$dtb_product_categories T2 JOIN dtb_category T3 ON T2.category_id = T3.category_id";
+                $where = 'T2.product_id = alldtl.product_id';
+                $objQuery->setOrder('T3.rank DESC, T2.rank DESC');
+                $objQuery->setLimit(1);
+                $sub_sql = $objQuery->getSqlWithLimitOffset($col, $from, $where);
+
+                $objQuery->setOrder("($sub_sql) DESC ,product_id DESC");
                 break;
         }
Index: /branches/version-2_13-dev/data/class/SC_Query.php
===================================================================
--- /branches/version-2_13-dev/data/class/SC_Query.php	(revision 23373)
+++ /branches/version-2_13-dev/data/class/SC_Query.php	(revision 23378)
@@ -1216,3 +1216,21 @@
         }
     }
+
+    /**
+     * 構築した SELECT 文を LIMIT OFFSET も含め取得する.
+     *
+     * @param  string SELECT 文に含めるカラム名
+     * @param  string SELECT 文に含めるテーブル名
+     * @param  string SELECT 文に含める WHERE 句
+     * @return string 構築済みの SELECT 文
+     */
+    function getSqlWithLimitOffset($cols, $from = '', $where = '')
+    {
+        $sql = $this->getSql($cols, $from, $where);
+        $offset = $this->conn->offset;
+        $limit = $this->conn->limit;
+        $this->setLimitOffset(0, 0);
+
+        return $this->dbFactory->addLimitOffset($sql, $limit, $offset);
+    }
 }
Index: /branches/version-2_13-dev/data/class/SC_Product.php
===================================================================
--- /branches/version-2_13-dev/data/class/SC_Product.php	(revision 23230)
+++ /branches/version-2_13-dev/data/class/SC_Product.php	(revision 23378)
@@ -82,15 +82,9 @@
             $o_table = $this->arrOrderData['table'];
             $o_order = $this->arrOrderData['order'];
-            $order = <<< __EOS__
-                    (
-                        SELECT $o_col
-                        FROM
-                            $o_table as T2
-                        WHERE T2.product_id = alldtl.product_id
-                        ORDER BY T2.$o_col $o_order
-                        LIMIT 1
-                    ) $o_order, product_id
-__EOS__;
-            $objQuery->setOrder($order);
+            $objQuery->setOrder("T2.$o_col $o_order");
+            $objQuery->setLimit(1);
+            $sub_sql = $objQuery->getSqlWithLimitOffset($o_col, "$o_table AS T2", 'T2.product_id = alldtl.product_id');
+
+            $objQuery->setOrder("($sub_sql) $o_order, product_id");
         }
         $arrReturn = $objQuery->getCol('alldtl.product_id', $table, '', $arrVal);
