Ticket #2512: zip_insert.patch

File zip_insert.patch, 3.2 KB (added by nanasess, 10 years ago)

SC_Query::prepare(), SC_Query::execute() を適切に使用したパッチ。 pg_* 関数を使用した処理もコメントにて記載。

  • data/class/pages/admin/basis/LC_Page_Admin_Basis_ZipInstall.php

    a b class LC_Page_Admin_Basis_ZipInstall extends LC_Page_Admin_Ex 
    233233        $img_cnt = 0; 
    234234 
    235235        $fp = $this->openZipCsv(); 
    236         while (!feof($fp)) { 
    237             $arrCSV = fgetcsv($fp, ZIP_CSV_LINE_MAX); 
    238             if (empty($arrCSV)) continue; 
    239             $cntCurrentLine++; 
    240             if ($cntCurrentLine >= $start) { 
    241                 $sqlval = array(); 
    242                 $sqlval['zip_id'] = $cntCurrentLine; 
    243                 $sqlval['zipcode'] = $arrCSV[2]; 
    244                 $sqlval['state'] = $arrCSV[6]; 
    245                 $sqlval['city'] = $arrCSV[7]; 
    246                 $sqlval['town'] = $arrCSV[8]; 
    247                 $objQuery->insert('mtb_zip', $sqlval); 
     236        $begin = microtime(true); 
     237 
     238        if ($fp !== false) { 
     239            $line = file(ZIP_CSV_UTF8_REALFILE); 
     240            // $dbconn = pg_connect("host=127.0.0.1 dbname=eccube_213 user=kentaro_ohkouchi password=foo"); 
     241            // pg_query($dbconn, 'BEGIN'); 
     242            // $result = pg_prepare($dbconn, 'zip_insert', 'INSERT INTO mtb_zip (zip_id, zipcode, state, city, town) VALUES ($1, $2, $3, $4, $5)'); 
     243            $objQuery->begin(); 
     244            $sth = $objQuery->prepare('INSERT INTO mtb_zip (zip_id, zipcode, state, city, town) VALUES (?, ?, ?, ?, ?)', null, MDB2_PREPARE_MANIP); 
     245 
     246            for($i = 0; $line[$i] != ''; $i ++){ 
     247                $array = explode(",", $line[$i]); 
     248                // pg_send_execute($dbconn, 'zip_insert', array($i, $array[2], $array[6], $array[7], $array[8])); 
     249                $objQuery->execute($sth, array($i, $array[2], $array[6], $array[7], $array[8])); 
     250 
     251                if ($i % $disp_line == 0 && $img_cnt < IMAGE_MAX) { 
     252                    echo '<img src="' . $img_path . 'graph_1_w.gif">'; 
     253                    SC_Utils_Ex::sfFlush(); 
     254                    $img_cnt++; 
     255                } 
     256                SC_Utils_Ex::extendTimeOut(); 
    248257                $cntInsert++; 
    249258            } 
    250259 
    251             // $disp_line件ごとに進捗表示する 
    252             if ($cntCurrentLine % $disp_line == 0 && $img_cnt < IMAGE_MAX) { 
    253                 echo '<img src="' . $img_path . 'graph_1_w.gif">'; 
    254                 SC_Utils_Ex::sfFlush(); 
    255                 $img_cnt++; 
    256             } 
    257             SC_Utils_Ex::extendTimeOut(); 
     260            $objQuery->commit(); 
     261            // pg_query($dbconn, 'COMMIT'); 
     262            // pg_close($dbconn); 
     263 
    258264        } 
     265 
     266        $end = microtime(true); 
    259267        fclose($fp); 
    260268 
    261269        echo '<img src="' . $img_path . 'space_w.gif">'; 
    class LC_Page_Admin_Basis_ZipInstall extends LC_Page_Admin_Ex 
    270278                    document.open('text/html','replace'); 
    271279                    document.clear(); 
    272280                    document.write('<p>完了しました。<br />'); 
    273                     document.write("<?php echo $cntInsert ?> 件を追加しました。</p>"); 
     281                    document.write("<?php echo $cntInsert ?> 件を追加しました。<?php echo ($end-$begin); ?> 秒かかりました</p>"); 
    274282                    document.write("<p><a href='?' target='_top'>戻る</a></p>"); 
    275283                    document.close(); 
    276284                }