/** * * Alters the table based on $this->col and $this->idx. * * @access public * * @return mixed Boolean true if altering was successful or a PEAR_Error on * failure. * * @see DB_Table_Manager::alter() * */ function alter() { $create = false; // alter the table columns and indexes if the table exists $table_exists = DB_Table_Manager::tableExists($this->db, $this->table); if (PEAR::isError($table_exists)) { return $table_exists; } if (!$table_exists) { // table does not exist => just create the table, there is // nothing that could be altered $create = true; } if ($create) { return DB_Table_Manager::create($this->db, $this->table, $this->col, $this->idx); } return DB_Table_Manager::alter($this->db, $this->table, $this->col, $this->idx); }
/** * * Creates the table based on $this->col and $this->idx. * * @access public * * @param mixed $flag Boolean false to abort the create attempt from * the start, 'drop' to drop the existing table and * re-create it, or 'safe' to only create the table if it * does not exist in the database. * * @return mixed Boolean false if there was no attempt to create the * table, boolean true if the attempt succeeded, or a PEAR_Error if * the attempt failed. * * @see DB_Table_Manager::create() * */ function create($flag) { // are we OK to create the table? $ok = false; // check the create-flag switch ($flag) { case 'drop': // forcibly drop an existing table $this->db->query("DROP TABLE {$this->table}"); $ok = true; break; case 'safe': // create only if table does not exist $list = $this->db->getListOf('tables'); // ok to create only if table does not exist $ok = !in_array($this->table, $list); break; default: // unknown flag return $this->throwError(DB_TABLE_ERR_CREATE_FLAG, "('{$flag}')"); } // are we going to create the table? if (!$ok) { return false; } else { include_once 'DB/Table/Manager.php'; return DB_Table_Manager::create($this->db, $this->table, $this->col, $this->idx, $flag); } }