/** * @param bool $wants_sql * @return bool|string * @throws Ruckusing_Exception */ public function finish($wants_sql = false) { if (!$this->_initialized) { throw new Ruckusing_Exception(sprintf("Table Definition: '%s' has not been initialized", $this->_name), Ruckusing_Exception::INVALID_TABLE_DEFINITION); } if (is_array($this->_options) && array_key_exists('options', $this->_options)) { $opt_str = $this->_options['options']; } else { $opt_str = null; } $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', 'primary_key'); $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); } }
/** * Column definition * * @param string $column_name the column name * @param string $type the type of the column * @param array $options column options * * @return string */ public function column_definition($column_name, $type, $options = null) { $col = new Ruckusing_Adapter_ColumnDefinition($this, $column_name, $type, $options); return $col->__toString(); }
/** * Table definition * * @param boolean $wants_sql * * @throws Ruckusing_Exception * @return boolean | 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); } }