Ignore:
Timestamp:
2012/03/16 20:14:58 (12 years ago)
Author:
Seasoft
Message:

#1666 (create_table_*.sql 間の差異を減らす)

  • インストーラから SC_DB_DBFactory_Ex#initObjQuery が呼ばれていない不具合を回避。
  • インストーラから誤ったDB用の SC_DB_DBFactory_Ex#initObjQuery が呼ばれる不具合を修正。

#1613 (typo修正・ソース整形・ソースコメントの改善)

Location:
branches/version-2_12-dev
Files:
2 edited

Legend:

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

    r21589 r21651  
    7878            $this->conn->setFetchMode(MDB2_FETCHMODE_ASSOC); 
    7979        } 
    80         $this->dbFactory = SC_DB_DBFactory_Ex::getInstance(); 
     80 
     81        // XXX 上書きインストール時にDBを変更するケースを想定し第1引数を与えている。 
     82        $this->dbFactory = SC_DB_DBFactory_Ex::getInstance($this->conn->dsn['phptype']); 
    8183        $this->dbFactory->initObjQuery($this); 
     84 
    8285        $this->force_run = $force_run; 
    8386    } 
  • branches/version-2_12-dev/html/install/index.php

    r21576 r21651  
    120120    // テーブルの作成 
    121121    case 'step3': 
    122         // 入力データを渡す。 
    123         $arrRet = $objDBParam->getHashArray(); 
    124         define('DB_TYPE', $arrRet['db_type']); 
    125         $dsn = $arrRet['db_type'] . '://' . $arrRet['db_user'] . ':' . $arrRet['db_password'] . '@' . $arrRet['db_server'] . ':' . $arrRet['db_port'] . '/' . $arrRet['db_name']; 
     122        $arrDsn = getArrayDsn($objDBParam); 
    126123 
    127124        if (count($objPage->arrErr) == 0) { 
     
    135132 
    136133        // テーブルの作成 
    137         $objPage->arrErr = lfExecuteSQL('./sql/create_table_' . $arrRet['db_type'] . '.sql', $dsn); 
     134        $objPage->arrErr = lfExecuteSQL('./sql/create_table_' . $arrDsn['phptype'] . '.sql', $arrDsn); 
    138135        if (count($objPage->arrErr) == 0) { 
    139136            $objPage->tpl_message .= '○:テーブルの作成に成功しました。<br />'; 
     
    144141        // 初期データの作成 
    145142        if (count($objPage->arrErr) == 0) { 
    146             $objPage->arrErr = lfExecuteSQL('./sql/insert_data.sql', $dsn); 
     143            $objPage->arrErr = lfExecuteSQL('./sql/insert_data.sql', $arrDsn); 
    147144            if (count($objPage->arrErr) == 0) { 
    148145                $objPage->tpl_message .= '○:初期データの作成に成功しました。<br />'; 
     
    154151        // シーケンスの作成 
    155152        if (count($objPage->arrErr) == 0) { 
    156             $objPage->arrErr = lfCreateSequence(getSequences(), $dsn); 
     153            $objPage->arrErr = lfCreateSequence(getSequences(), $arrDsn); 
    157154            if (count($objPage->arrErr) == 0) { 
    158155                $objPage->tpl_message .= '○:シーケンスの作成に成功しました。<br />'; 
     
    175172    // テーブル類削除 
    176173    case 'drop': 
    177         // 入力データを渡す。 
    178         $arrRet = $objDBParam->getHashArray(); 
    179         if (!defined('DB_TYPE')) { 
    180             define('DB_TYPE', $arrRet['db_type']); 
    181         } 
    182         $dsn = $arrRet['db_type'] . '://' . $arrRet['db_user'] . ':' . $arrRet['db_password'] . '@' . $arrRet['db_server'] . ':' . $arrRet['db_port'] . '/' . $arrRet['db_name']; 
     174        $arrDsn = getArrayDsn($objDBParam); 
    183175 
    184176        // テーブルの削除 
    185177        if (count($objPage->arrErr) == 0) { 
    186             $objPage->arrErr = lfExecuteSQL('./sql/drop_table.sql', $dsn, false); 
     178            $objPage->arrErr = lfExecuteSQL('./sql/drop_table.sql', $arrDsn, false); 
    187179            if (count($objPage->arrErr) == 0) { 
    188180                $objPage->tpl_message .= '○:テーブルの削除に成功しました。<br />'; 
     
    194186        // シーケンスの削除 
    195187        if (count($objPage->arrErr) == 0) { 
    196             $objPage->arrErr = lfDropSequence(getSequences(), $dsn); 
     188            $objPage->arrErr = lfDropSequence(getSequences(), $arrDsn); 
    197189            if (count($objPage->arrErr) == 0) { 
    198190                $objPage->tpl_message .= '○:シーケンスの削除に成功しました。<br />'; 
     
    502494    if (!ereg('/$', $normal_url)) $normal_url = $normal_url . '/'; 
    503495 
    504     $arrDbParam = $objDBParam->getHashArray(); 
    505     if (!defined('DB_TYPE')) { 
    506         define('DB_TYPE', $arrDbParam['db_type']); 
    507     } 
    508     $dsn = $arrDbParam['db_type'] . '://' . $arrDbParam['db_user'] . ':' . $arrDbParam['db_password'] . '@' . $arrDbParam['db_server'] . ':' . $arrDbParam['db_port'] . '/' . $arrDbParam['db_name']; 
    509     if (!defined('DEFAULT_DSN')) { 
    510         define('DEFAULT_DSN', $dsn); 
    511     } 
     496    $arrDsn = getArrayDsn($objDBParam); 
    512497 
    513498    $objPage->tpl_site_url = $normal_url; 
     
    515500    $objPage->tpl_cube_ver = ECCUBE_VERSION; 
    516501    $objPage->tpl_php_ver = phpversion(); 
    517     $dbFactory = SC_DB_DBFactory_Ex::getInstance($arrDbParam['db_type']); 
    518     $objPage->tpl_db_ver = $dbFactory->sfGetDBVersion($dsn); 
     502    $dbFactory = SC_DB_DBFactory_Ex::getInstance($arrDsn['phptype']); 
     503    $objPage->tpl_db_ver = $dbFactory->sfGetDBVersion($arrDsn); 
    519504    $objPage->tpl_db_skip = $_POST['db_skip']; 
    520505    $objPage->tpl_mainpage = 'step4.tpl'; 
     
    532517    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray()); 
    533518 
    534     // ショップマスター情報の書き込み 
    535     $arrRet = $objDBParam->getHashArray(); 
    536  
    537     $dsn = $arrRet['db_type'] . '://' . $arrRet['db_user'] . ':' . $arrRet['db_password'] . '@' . $arrRet['db_server'] . ':' . $arrRet['db_port'] . '/' . $arrRet['db_name']; 
     519    $arrDsn = getArrayDsn($objDBParam); 
     520 
    538521    $sqlval['shop_name'] = $objWebParam->getValue('shop_name'); 
    539522    $sqlval['email01'] = $objWebParam->getValue('admin_mail'); 
     
    547530    $sqlval['mypage_tpl'] = 'default1'; 
    548531    $sqlval['update_date'] = 'CURRENT_TIMESTAMP'; 
    549     $objQuery = new SC_Query($dsn); 
     532    $objQuery = new SC_Query($arrDsn); 
    550533    $cnt = $objQuery->count('dtb_baseinfo'); 
    551534    if ($cnt > 0) { 
     
    706689 
    707690// 入力内容のチェック 
    708 function lfCheckWebError($objFormParam) { 
     691function lfCheckWebError($objWebParam) { 
    709692    // 入力データを渡す。 
    710     $arrRet = $objFormParam->getHashArray(); 
     693    $arrRet = $objWebParam->getHashArray(); 
    711694    $objErr = new SC_CheckError($arrRet); 
    712     $objErr->arrErr = $objFormParam->checkError(); 
     695    $objErr->arrErr = $objWebParam->checkError(); 
    713696 
    714697    // ディレクトリ名のみ取得する 
     
    725708 
    726709    // パスワードのチェック 
    727     $objErr->doFunc( array('管理者:パスワード', 'login_pass', ID_MIN_LEN, ID_MAX_LEN), array('SPTAB_CHECK', 'NUM_RANGE_CHECK')); 
     710    $objErr->doFunc(array('管理者:パスワード', 'login_pass', ID_MIN_LEN, ID_MAX_LEN), array('SPTAB_CHECK', 'NUM_RANGE_CHECK')); 
    728711 
    729712    // 管理機能ディレクトリのチェック 
    730     $objErr->doFunc( array('管理機能:ディレクトリ', 'admin_dir', ID_MIN_LEN, ID_MAX_LEN), array('SPTAB_CHECK', 'NUM_RANGE_CHECK')); 
     713    $objErr->doFunc(array('管理機能:ディレクトリ', 'admin_dir', ID_MIN_LEN, ID_MAX_LEN), array('SPTAB_CHECK', 'NUM_RANGE_CHECK')); 
    731714 
    732715    $oldAdminDir = SC_Utils_Ex::sfTrimURL(ADMIN_DIR); 
    733     $newAdminDir = $objFormParam->getValue('admin_dir'); 
     716    $newAdminDir = $objWebParam->getValue('admin_dir'); 
    734717    if ($oldAdminDir !== $newAdminDir AND file_exists(HTML_REALDIR . $newAdminDir) and $newAdminDir != 'admin') { 
    735718        $objErr->arrErr['admin_dir'] = '※ 指定した管理機能ディレクトリは既に存在しています。別の名前を指定してください。'; 
     
    740723 
    741724// 入力内容のチェック 
    742 function lfCheckDBError($objFormParam) { 
     725function lfCheckDBError($objDBParam) { 
    743726    global $objPage; 
    744727 
    745728    // 入力データを渡す。 
    746     $arrRet = $objFormParam->getHashArray(); 
     729    $arrRet = $objDBParam->getHashArray(); 
    747730 
    748731    $objErr = new SC_CheckError($arrRet); 
    749     $objErr->arrErr = $objFormParam->checkError(); 
     732    $objErr->arrErr = $objDBParam->checkError(); 
    750733 
    751734    if (count($objErr->arrErr) == 0) { 
    752         if (!defined('DB_TYPE')) { 
    753             define('DB_TYPE', $arrRet['db_type']); 
    754         } 
    755         // 接続確認 
    756         $dsn = $arrRet['db_type'] . '://' . $arrRet['db_user'] . ':' . $arrRet['db_password'] . '@' . $arrRet['db_server'] . ':' . $arrRet['db_port'] . '/' . $arrRet['db_name']; 
     735        $arrDsn = getArrayDsn($objDBParam); 
    757736        // Debugモード指定 
    758737        $options['debug'] = PEAR_DB_DEBUG; 
    759         $objDB = MDB2::connect($dsn, $options); 
     738        $objDB = MDB2::connect($arrDsn, $options); 
    760739        // 接続成功 
    761740        if (!PEAR::isError($objDB)) { 
    762             $dbFactory = SC_DB_DBFactory_Ex::getInstance($arrRet['db_type']); 
     741            $dbFactory = SC_DB_DBFactory_Ex::getInstance($arrDsn['phptype']); 
    763742            // データベースバージョン情報の取得 
    764             $objPage->tpl_db_version = $dbFactory->sfGetDBVersion($dsn); 
     743            $objPage->tpl_db_version = $dbFactory->sfGetDBVersion($arrDsn); 
    765744        } else { 
    766745            $objErr->arrErr['all'] = '>> ' . $objDB->message . '<br />'; 
     
    775754 
    776755// SQL文の実行 
    777 function lfExecuteSQL($filepath, $dsn, $disp_err = true) { 
     756function lfExecuteSQL($filepath, $arrDsn, $disp_err = true) { 
    778757    $arrErr = array(); 
    779758 
     
    787766        // Debugモード指定 
    788767        $options['debug'] = PEAR_DB_DEBUG; 
    789         $objDB = MDB2::connect($dsn, $options); 
     768        $objDB = MDB2::connect($arrDsn, $options); 
    790769        // 接続エラー 
    791770        if (!PEAR::isError($objDB)) { 
    792771            $objDB->setCharset('utf8'); 
     772 
     773            // MySQL 用の初期化 
     774            // XXX SC_Query を使うようにすれば、この処理は不要となる 
     775            if ($arrDsn['phptype'] === 'mysql') { 
     776                $objDB->exec('SET SESSION storage_engine = InnoDB'); 
     777                $objDB->exec("SET SESSION sql_mode = 'ANSI'"); 
     778            } 
     779 
    793780            $sql_split = split(';', $sql); 
    794781            foreach ($sql_split as $key => $val) { 
     
    821808 * 
    822809 * @param array $arrSequences シーケンスのテーブル名, カラム名の配列 
    823  * @param string $dsn データソース名 
     810 * @param array $arrDsn データソース名の配列 
    824811 * @return array エラーが発生した場合はエラーメッセージの配列 
    825812 */ 
    826 function lfDropSequence($arrSequences, $dsn) { 
     813function lfDropSequence($arrSequences, $arrDsn) { 
    827814    $arrErr = array(); 
    828815 
    829816    // Debugモード指定 
    830817    $options['debug'] = PEAR_DB_DEBUG; 
    831     $objDB = MDB2::connect($dsn, $options); 
     818    $objDB = MDB2::connect($arrDsn, $options); 
    832819    $objManager =& $objDB->loadModule('Manager'); 
    833820 
     
    860847 * 
    861848 * @param array $arrSequences シーケンスのテーブル名, カラム名の配列 
    862  * @param string $dsn データソース名 
     849 * @param array $arrDsn データソース名の配列 
    863850 * @return array エラーが発生した場合はエラーメッセージの配列 
    864851 */ 
    865 function lfCreateSequence($arrSequences, $dsn) { 
     852function lfCreateSequence($arrSequences, $arrDsn) { 
    866853    $arrErr = array(); 
    867854 
    868855    // Debugモード指定 
    869856    $options['debug'] = PEAR_DB_DEBUG; 
    870     $objDB = MDB2::connect($dsn, $options); 
     857    $objDB = MDB2::connect($arrDsn, $options); 
    871858    $objManager =& $objDB->loadModule('Manager'); 
    872859 
     
    10731060    return true; 
    10741061} 
     1062 
     1063function getArrayDsn(SC_FormParam $objDBParam) { 
     1064    $arrRet = $objDBParam->getHashArray(); 
     1065 
     1066    if (!defined('DB_TYPE')) { 
     1067        define('DB_TYPE', $arrRet['db_type']); 
     1068    } 
     1069 
     1070    $arrDsn = array( 
     1071        'phptype'   => $arrRet['db_type'], 
     1072        'username'  => $arrRet['db_user'], 
     1073        'password'  => $arrRet['db_password'], 
     1074        'hostspec'  => $hostspec, 
     1075        'port'      => $arrRet['db_port'], 
     1076        'database'  => $arrRet['db_name'], 
     1077    ); 
     1078 
     1079    // 文字列形式の DSN との互換処理 
     1080    if ($arrRet['db_server'] !== '+') { 
     1081        $arrDsn['hostspec'] = $arrRet['db_server']; 
     1082        $arrDsn['port']     = $arrRet['db_port']; 
     1083    } 
     1084 
     1085    return $arrDsn; 
     1086} 
Note: See TracChangeset for help on using the changeset viewer.