db = $db; $this->table_name = $tbl_name; } function _get_column_definition($col_name, $type, $required, $default_value) { $ret_val = "$col_name $type"; if($required) { $ret_val .= ' NOT NULL'; } if(!empty($default_value)) { $ret_val .= " DEFAULT '$default_value'"; } return $ret_val; } function create_table() { $column_definition = $this->_get_column_definition('id', 'varchar(100)', true, ''); $query = "CREATE TABLE {$this->table_name} ($column_definition);"; $result = $this->db->query($query, true, 'CustomFieldsTableSchema::create_table'); return $result; } function add_column($column_name, $data_type, $required, $default_value) { $column_definition = $this->_get_column_definition($column_name, $data_type, $required, $default_value); $query = "ALTER TABLE {$this->table_name} " . "ADD COLUMN $column_definition;"; $result = $this->db->query($query, true, 'CustomFieldsTableSchema::add_column'); return $result; } function modify_column($column_name, $data_type, $required, $default_value) { $column_definition = $this->_get_column_definition($column_name, $data_type, $required, $default_value); $query = "ALTER TABLE {$this->table_name} " . "MODIFY COLUMN $column_definition;"; $result = $this->db->query($query, true, 'CustomFieldsTableSchema::modify_column'); return $result; } function drop_column($column_name) { $query = "ALTER TABLE $this->table_name " . "DROP COLUMN $column_name;"; $result = $this->db->query($query, true, 'CustomFieldsTableSchema::drop_column'); return $result; } function _get_custom_tables() { $pattern = '%' . CUSTOMFIELDSTABLE_CUSTOM_TABLE_SUFFIX; if ($this->db){ if ($this->db->dbType == 'mysql'){ $result = $this->db->query("SHOW TABLES LIKE '".$pattern."'"); $rows=$this->db->fetchByAssoc($result); return $rows; }else if ($this->dbType == 'oci8') { } } return false; } /** * @static */ function custom_table_exists($tbl_name) { $db = DBManagerFactory::getInstance(); return $db->tableExists($tbl_name); } } ?>