Example #1
0
 /**
  * finish
  *
  * @param boolean $wants_sql Flag to get SQL generated
  *
  * @return mixed
  * @throws Phigrate_Exception_InvalidTableDefinition
  */
 public function finish($wants_sql = false)
 {
     if ($this->_initialized == false) {
         require_once 'Phigrate/Exception/InvalidTableDefinition.php';
         throw new Phigrate_Exception_InvalidTableDefinition(sprintf("Table Definition: '%s' has not been initialized", $this->_name));
     }
     $opt_str = null;
     if (is_array($this->_options) && array_key_exists('options', $this->_options)) {
         $opt_str = ' ' . $this->_options['options'];
     }
     $close_sql = sprintf(')%s', $opt_str);
     $createTableSql = $this->_sql;
     if ($this->_autoGenerateId === true) {
         $this->_primaryKeys[] = 'id';
         $primary_id = new Phigrate_Adapter_Mysql_ColumnDefinition($this->_adapter, $this->_prefix . 'id', 'integer', array('unsigned' => true, 'null' => false, 'auto_increment' => true));
         $createTableSql .= $primary_id->toSql() . ",\n";
     }
     $createTableSql .= $this->_columnsToStr();
     $createTableSql .= $this->_keys() . $close_sql . $this->_adapter->getDelimiter();
     if ($wants_sql) {
         return $createTableSql;
     }
     return $this->_adapter->executeDdl($createTableSql);
 }