Last active
August 29, 2015 13:57
-
-
Save zenith6/9412002 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Index: data/class/pages/admin/basis/LC_Page_Admin_Basis_ZipInstall.php | |
| =================================================================== | |
| --- data/class/pages/admin/basis/LC_Page_Admin_Basis_ZipInstall.php (revision 23350) | |
| +++ data/class/pages/admin/basis/LC_Page_Admin_Basis_ZipInstall.php (working copy) | |
| @@ -233,19 +233,28 @@ | |
| $img_cnt = 0; | |
| $fp = $this->openZipCsv(); | |
| + $begin = microtime(true); | |
| + $bulk_size = 100; # バルクインサート件数 | |
| + $insert_expr = 'INSERT INTO mtb_zip (zip_id, zipcode, state, city, town)'; | |
| + $values_ph = '(' . implode(',', array_fill(0, 5, '?')) . ')'; | |
| + $values_expr = 'VALUES ' . implode(',', array_fill(0, $bulk_size, $values_ph)); | |
| + $stmt = $objQuery->prepare($insert_expr . ' ' . $values_expr, null, MDB2_PREPARE_MANIP); | |
| + $values = array(); | |
| while (!feof($fp)) { | |
| $arrCSV = fgetcsv($fp, ZIP_CSV_LINE_MAX); | |
| if (empty($arrCSV)) continue; | |
| $cntCurrentLine++; | |
| if ($cntCurrentLine >= $start) { | |
| - $sqlval = array(); | |
| - $sqlval['zip_id'] = $cntCurrentLine; | |
| - $sqlval['zipcode'] = $arrCSV[2]; | |
| - $sqlval['state'] = $arrCSV[6]; | |
| - $sqlval['city'] = $arrCSV[7]; | |
| - $sqlval['town'] = $arrCSV[8]; | |
| - $objQuery->insert('mtb_zip', $sqlval); | |
| + $values[] = $cntCurrentLine; | |
| + $values[] = $arrCSV[2]; | |
| + $values[] = $arrCSV[6]; | |
| + $values[] = $arrCSV[7]; | |
| + $values[] = $arrCSV[8]; | |
| $cntInsert++; | |
| + if ($cntInsert % $bulk_size == 0) { | |
| + $objQuery->execute($stmt, $values); | |
| + $values = array(); | |
| + } | |
| } | |
| // $disp_line件ごとに進捗表示する | |
| @@ -257,8 +266,14 @@ | |
| SC_Utils_Ex::extendTimeOut(); | |
| } | |
| fclose($fp); | |
| + if ($values) { | |
| + $values_expr = 'VALUES ' . implode(',', array_fill(0, $cntInsert % $bulk_size, $values_ph)); | |
| + $stmt = $insert_expr . ' ' . $values_expr; | |
| + $objQuery->query($stmt, $values); | |
| + } | |
| echo '<img src="' . $img_path . 'space_w.gif">'; | |
| + $end = microtime(true); | |
| ?> | |
| </div> | |
| @@ -270,7 +285,7 @@ | |
| document.open('text/html','replace'); | |
| document.clear(); | |
| document.write('<p>完了しました。<br />'); | |
| - document.write("<?php echo $cntInsert ?> 件を追加しました。</p>"); | |
| + document.write("<?php echo $cntInsert ?> 件を追加しました。<?php echo ($end-$begin); ?> 秒かかりました</p>"); | |
| document.write("<p><a href='?' target='_top'>戻る</a></p>"); | |
| document.close(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment