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);
}
}