Gdn_DatabaseStructure::set PHP Method

set() public method

Creates the table and columns specified with $this->Table() and $this->Column(). If no table or columns have been specified, this method will throw a fatal error.
public set ( boolean $Explicit = false, boolean $Drop = false )
$Explicit boolean If TRUE, and the table specified with $this->Table() already exists, this method will remove any columns from the table that were not defined with $this->Column().
$Drop boolean If TRUE, and the table specified with $this->Table() already exists, this method will drop the table before attempting to re-create it.
    public function set($Explicit = false, $Drop = false)
    {
        /// Throw an event so that the structure can be overridden.
        $this->EventArguments['Explicit'] = $Explicit;
        $this->EventArguments['Drop'] = $Drop;
        $this->fireEvent('BeforeSet');
        try {
            // Make sure that table and columns have been defined
            if ($this->_TableName == '') {
                throw new Exception(T('You must specify a table before calling DatabaseStructure::Set()'));
            }
            if (count($this->_Columns) == 0) {
                throw new Exception(T('You must provide at least one column before calling DatabaseStructure::Set()'));
            }
            if ($this->tableExists()) {
                if ($Drop) {
                    // Drop the table.
                    $this->drop();
                    // And re-create it.
                    return $this->_create();
                }
                // If the table already exists, go into modify mode.
                return $this->_modify($Explicit, $Drop);
            } else {
                // If it doesn't already exist, go into create mode.
                return $this->_create();
            }
        } catch (Exception $Ex) {
            $this->reset();
            throw $Ex;
        }
    }