開発メモ

開発用のメモです。

ECCUBE テーブル・カラムの存在確認

<?php
if (DB_TYPE == "mysql") {
    $tables_sql = "SELECT DISTINCT 1 AS cont FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = ? AND table_name = ?";
    $colmun_sql = "SELECT DISTINCT 1 AS cont FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = ? AND table_name = ? AND column_name LIKE 'plg_productsAddColumn%' AND column_name = ?";
} else {
    // XXX postgres 動作確認 未
    $tables_sql = "SELECT DISTINCT 1 AS cont as cont FROM information_schema.columns WHERE table_catalog = ? AND table_name = ? ";
    $tables_sql = "SELECT DISTINCT 1 AS cont as cont FROM information_schema.columns WHERE table_catalog = ? AND table_name = ? AND column_name LIKE 'plg_productsAddColumn%' AND column_name = ?";
}
if (count($objQuery -> getAll($tables_sql, array(DB_NAME, this -> arrForm["table_name"]["value"]))) == 0) {
    $this -> arrErr["table_name"] = $this -> arrForm['table_name']['disp_name'] . "の値が無効です。<br/>\n";
} else if (strlen($this -> arrForm['column_name']["value"]) > 0) {
    if (count($objQuery -> getAll($colmun_sql, array(
            DB_NAME, $this -> arrForm["table_name"]["value"], $this -> arrForm["column_name"]["value"] ))) == 0) {
        $this -> arrErr["column_name"] = $this -> arrForm['column_name']['disp_name'] . "の値が無効です。<br/>\n";
    }
}
Twitter: @asahina_alice