Exemplo n.º 1
0
 /**
  * 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.
  *
  * @param boolean $Explicit 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().
  * @param boolean $Drop 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)
 {
     // Make sure that table and columns have been defined
     if ($this->_TableName == '') {
         throw new Exception(Gdn::Translate('You must specify a table before calling DatabaseStructure::Set()'));
     }
     if (count($this->_Columns) == 0) {
         throw new Exception(Gdn::Translate('You must provide at least one column before calling DatabaseStructure::Set()'));
     }
     // Be sure to convert names to lowercase before comparing because
     // different operating systems/databases vary on how case-sensitivity is
     // handled in table names.
     $SQL = $this->Database->SQL();
     $Tables = $SQL->FetchTables();
     if (in_array(strtolower($this->_DatabasePrefix . $this->_TableName), array_map('strtolower', $Tables))) {
         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();
     }
 }
 /** Gets the column definitions for the columns in the database.
  * @return array
  */
 public function ExistingColumns() {
    if($this->_ExistingColumns === NULL) {
       if($this->TableExists())
          $this->_ExistingColumns = $this->Database->SQL()->FetchTableSchema($this->_TableName);
       else
          $this->_ExistingColumns = array();
    }
    return $this->_ExistingColumns;
 }