Ruckusing_Adapter_MySQL_TableDefinition::finish PHP Method

finish() public method

Table definition
public finish ( boolean $wants_sql = false ) : boolean | string
$wants_sql boolean
return boolean | string | string
    public function finish($wants_sql = false)
    {
        if ($this->_initialized == false) {
            throw new Ruckusing_Exception(sprintf("Table Definition: '%s' has not been initialized", $this->_name), Ruckusing_Exception::INVALID_TABLE_DEFINITION);
        }
        $opt_str = '';
        if (is_array($this->_options) && array_key_exists('options', $this->_options)) {
            $opt_str = $this->_options['options'];
        } else {
            if (isset($this->_adapter->db_info['charset'])) {
                $opt_str = " DEFAULT CHARSET=" . $this->_adapter->db_info['charset'];
            } else {
                $opt_str = " DEFAULT CHARSET=utf8";
            }
        }
        $close_sql = sprintf(") %s;", $opt_str);
        $create_table_sql = $this->_sql;
        if ($this->_auto_generate_id === true) {
            $this->_primary_keys[] = 'id';
            $primary_id = new Ruckusing_Adapter_ColumnDefinition($this->_adapter, 'id', 'integer', array('unsigned' => true, 'null' => false, 'auto_increment' => true));
            $create_table_sql .= $primary_id->to_sql() . ",\n";
        }
        $create_table_sql .= $this->columns_to_str();
        $create_table_sql .= $this->keys() . $close_sql;
        if ($wants_sql) {
            return $create_table_sql;
        } else {
            return $this->_adapter->execute_ddl($create_table_sql);
        }
    }

Usage Example

 /**
  * test that we can generate a table w/o a primary key
  */
 public function test_generate_table_without_primary_key()
 {
     $t1 = new Ruckusing_Adapter_MySQL_TableDefinition($this->adapter, "users", array('id' => false, 'options' => 'Engine=InnoDB'));
     $t1->column("first_name", "string");
     $t1->column("last_name", "string", array('limit' => 32));
     $actual = $t1->finish();
     $col = $this->adapter->column_info("users", "id");
     $this->assertEquals(null, $col);
 }
All Usage Examples Of Ruckusing_Adapter_MySQL_TableDefinition::finish