/** * 規格データをコピーする * * @param array $arrList フォーム入力パラメーター配列 * @param SC_Query $objQuery SC_Queryインスタンス * @return boolean エラーフラグ */ public function lfCopyProductClass($arrList, &$objQuery) { // 複製元のdtb_products_classを取得(規格なしのため、1件のみの取得) $col = '*'; $table = 'dtb_products_class'; $where = 'product_id = ?'; $arrProductClass = $objQuery->select($col, $table, $where, array($arrList['copy_product_id'])); //トランザクション開始 $objQuery->begin(); $err_flag = false; //非編集項目は複製、編集項目は上書きして登録 foreach ($arrProductClass as $records) { foreach ($records as $key => $value) { if (isset($arrList[$key])) { switch ($key) { case 'stock_unlimited': $records[$key] = (int) $arrList[$key]; break; default: $records[$key] = $arrList[$key]; break; } } } $records['product_class_id'] = $objQuery->nextVal('dtb_products_class_product_class_id'); $records['update_date'] = 'CURRENT_TIMESTAMP'; $records['create_date'] = 'CURRENT_TIMESTAMP'; $objQuery->insert($table, $records); //エラー発生時は中断 if ($objQuery->isError()) { $err_flag = true; continue; } } //トランザクション終了 if ($err_flag) { $objQuery->rollback(); } else { $objQuery->commit(); } return !$err_flag; }
/** * カラムの存在チェックと作成を行う. * * チェック対象のテーブルに, 該当のカラムが存在するかチェックする. * 引数 $add が true の場合, 該当のカラムが存在しない場合は, カラムの生成を行う. * カラムの生成も行う場合は, $col_type も必須となる. * * @param string $table_name テーブル名 * @param string $column_name カラム名 * @param string $col_type カラムのデータ型 * @param string $dsn データソース名 * @param bool $add カラムの作成も行う場合 true * @return bool カラムが存在する場合とカラムの生成に成功した場合 true, * テーブルが存在しない場合 false, * 引数 $add == false でカラムが存在しない場合 false */ function sfColumnExists($table_name, $col_name, $col_type = "", $dsn = "", $add = false) { $dbFactory = SC_DB_DBFactory_Ex::getInstance(); $dsn = $dbFactory->getDSN($dsn); // テーブルが無ければエラー if (!$this->sfTabaleExists($table_name, $dsn)) { return false; } $objQuery = new SC_Query($dsn, true, true); // 正常に接続されている場合 if (!$objQuery->isError()) { list($db_type) = split(":", $dsn); // カラムリストを取得 $arrRet = $dbFactory->sfGetColumnList($table_name); if (count($arrRet) > 0) { if (in_array($col_name, $arrRet)) { return true; } } } // カラムを追加する if ($add) { $objQuery->query("ALTER TABLE {$table_name} ADD {$col_name} {$col_type} "); return true; } return false; }