Ignore:
Timestamp:
2012/08/30 14:15:56 (12 years ago)
Author:
shutta
Message:

refs #1925 (SC_Queryのupdateメソッドの使用を推奨)
SC_Queryのupdateメソッドを使用するように書き換えた。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_12-dev/data/class/helper/SC_Helper_DB.php

    r21927 r22012  
    985985            $uprank = $rank + 1; 
    986986            $up_id = $objQuery->get($colname, $table, $where, array($uprank)); 
     987 
    987988            // ランク入れ替えの実行 
    988             $sqlup = "UPDATE $table SET rank = ? WHERE $colname = ?"; 
     989            $where = "$colname = ?"; 
    989990            if ($andwhere != '') { 
    990                 $sqlup.= " AND $andwhere"; 
    991             } 
    992             $objQuery->exec($sqlup, array($rank + 1, $id)); 
    993             $objQuery->exec($sqlup, array($rank, $up_id)); 
     991                $where .= " AND $andwhere"; 
     992            } 
     993 
     994            $sqlval = array( 
     995                'rank' => $rank + 1, 
     996            ); 
     997            $arrWhereVal = array($id); 
     998            $objQuery->update($table, $sqlval, $where, $arrWhereVal); 
     999 
     1000            $sqlval = array( 
     1001                'rank' => $rank, 
     1002            ); 
     1003            $arrWhereVal = array($up_id); 
     1004            $objQuery->update($table, $sqlval, $where, $arrWhereVal); 
    9941005        } 
    9951006        $objQuery->commit(); 
     
    10241035            $downrank = $rank - 1; 
    10251036            $down_id = $objQuery->get($colname, $table, $where, array($downrank)); 
     1037 
    10261038            // ランク入れ替えの実行 
    1027             $sqlup = "UPDATE $table SET rank = ? WHERE $colname = ?"; 
     1039            $where = "$colname = ?"; 
    10281040            if ($andwhere != '') { 
    1029                 $sqlup.= " AND $andwhere"; 
    1030             } 
    1031             $objQuery->exec($sqlup, array($rank - 1, $id)); 
    1032             $objQuery->exec($sqlup, array($rank, $down_id)); 
     1041                $where .= " AND $andwhere"; 
     1042            } 
     1043 
     1044            $sqlval = array( 
     1045                'rank' => $rank - 1, 
     1046            ); 
     1047            $arrWhereVal = array($id); 
     1048            $objQuery->update($table, $sqlval, $where, $arrWhereVal); 
     1049 
     1050            $sqlval = array( 
     1051                'rank' => $rank, 
     1052            ); 
     1053            $arrWhereVal = array($down_id); 
     1054            $objQuery->update($table, $sqlval, $where, $arrWhereVal); 
    10331055        } 
    10341056        $objQuery->commit(); 
     
    10781100 
    10791101        // 指定した順位の商品から移動させる商品までのrankを1つずらす 
    1080         $sql = "UPDATE $tableName SET rank = $term WHERE rank BETWEEN ? AND ?"; 
     1102        $sqlval = array(); 
     1103        $arrRawSql = array( 
     1104            'rank' => $term, 
     1105        ); 
     1106        $str_where = 'rank BETWEEN ? AND ?'; 
    10811107        if ($where != '') { 
    1082             $sql.= " AND $where"; 
    1083         } 
    1084  
    1085         if ($position > $rank) $objQuery->exec($sql, array($rank + 1, $position)); 
    1086         if ($position < $rank) $objQuery->exec($sql, array($position, $rank - 1)); 
     1108            $str_where .= " AND $where"; 
     1109        } 
     1110 
     1111        if ($position > $rank) { 
     1112            $arrWhereVal = array($rank + 1, $position); 
     1113            $objQuery->update($tableName, $sqlval, $str_where, $arrWhereVal, $arrRawSql); 
     1114        } 
     1115        if ($position < $rank) { 
     1116            $arrWhereVal = array($position, $rank - 1); 
     1117            $objQuery->update($tableName, $sqlval, $str_where, $arrWhereVal, $arrRawSql); 
     1118        } 
    10871119 
    10881120        // 指定した順位へrankを書き換える。 
    1089         $sql  = "UPDATE $tableName SET rank = ? WHERE $keyIdColumn = ? "; 
     1121        $sqlval = array( 
     1122            'rank' => $position, 
     1123        ); 
     1124        $str_where = "$keyIdColumn = ?"; 
    10901125        if ($where != '') { 
    1091             $sql.= " AND $where"; 
    1092         } 
    1093  
    1094         $objQuery->exec($sql, array($position, $keyId)); 
     1126            $str_where .= " AND $where"; 
     1127        } 
     1128        $arrWhereVal = array($keyId); 
     1129        $objQuery->update($tableName, $sqlval, $str_where, $arrWhereVal); 
     1130 
    10951131        $objQuery->commit(); 
    10961132    } 
     
    11221158        if (!$delete) { 
    11231159            // ランクを最下位にする、DELフラグON 
    1124             $sqlup = "UPDATE $table SET rank = 0, del_flg = 1 "; 
    1125             $sqlup.= "WHERE $colname = ?"; 
    1126             // UPDATEの実行 
    1127             $objQuery->exec($sqlup, array($id)); 
     1160            $sqlval = array( 
     1161                'rank'      => 0, 
     1162                'del_flg'   => 1, 
     1163            ); 
     1164            $where = "$colname = ?"; 
     1165            $arrWhereVal = array($id); 
     1166            $objQuery->update($table, $sqlval, $where, $arrWhereVal); 
    11281167        } else { 
    11291168            $objQuery->delete($table, "$colname = ?", array($id)); 
     
    11311170 
    11321171        // 追加レコードのランクより上のレコードを一つずらす。 
     1172        $sqlval = array(); 
    11331173        $where = 'rank > ?'; 
    11341174        if ($andwhere != '') { 
    1135             $where.= " AND $andwhere"; 
    1136         } 
    1137         $sqlup = "UPDATE $table SET rank = (rank - 1) WHERE $where"; 
    1138         $objQuery->exec($sqlup, array($rank)); 
     1175            $where .= " AND $andwhere"; 
     1176        } 
     1177        $arrWhereVal = array($rank); 
     1178        $arrRawSql = array( 
     1179            'rank' => '(rank - 1)', 
     1180        ); 
     1181        $objQuery->update($table, $sqlval, $where, $arrWhereVal, $arrRawSql); 
     1182 
    11391183        $objQuery->commit(); 
    11401184    } 
     
    11701214    /** 
    11711215     * カテゴリ変更時の移動処理を行う. 
     1216     *  
     1217     * ※この関数って、どこからも呼ばれていないのでは?? 
    11721218     * 
    11731219     * @param SC_Query $objQuery SC_Query インスタンス 
     
    11861232        // 旧カテゴリでのランク削除処理 
    11871233        // 移動レコードのランクを取得する。 
     1234        $sqlval = array(); 
    11881235        $where = "$id_name = ?"; 
    11891236        $rank = $objQuery->get('rank', $table, $where, array($id)); 
    11901237        // 削除レコードのランクより上のレコードを一つ下にずらす。 
    11911238        $where = "rank > ? AND $cat_name = ?"; 
    1192         $sqlup = "UPDATE $table SET rank = (rank - 1) WHERE $where"; 
    1193         $objQuery->exec($sqlup, array($rank, $old_catid)); 
     1239        $arrWhereVal = array($rank, $old_catid); 
     1240        $arrRawSql = array( 
     1241            'rank' => '(rank - 1)', 
     1242        ); 
     1243        $objQuery->update($table, $sqlval, $where, $arrWhereVal, $arrRawSql); 
     1244 
    11941245        // 新カテゴリでの登録処理 
    11951246        // 新カテゴリの最大ランクを取得する。 
    11961247        $max_rank = $objQuery->max('rank', $table, "$cat_name = ?", array($new_catid)) + 1; 
     1248        $sqlval = array( 
     1249            'rank' => $max_rank, 
     1250        ); 
    11971251        $where = "$id_name = ?"; 
    1198         $sqlup = "UPDATE $table SET rank = ? WHERE $where"; 
    1199         $objQuery->exec($sqlup, array($max_rank, $id)); 
     1252        $arrWhereVal = array($id); 
     1253        $objQuery->update($table, $sqlval, $where, $arrWhereVal); 
    12001254    } 
    12011255 
Note: See TracChangeset for help on using the changeset viewer.