OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Parser::CreateDBStmt Class Reference

#include <ParserNode.h>

+ Inheritance diagram for Parser::CreateDBStmt:
+ Collaboration diagram for Parser::CreateDBStmt:

Public Member Functions

 CreateDBStmt (std::string *n, std::list< NameValueAssign * > *l, const bool if_not_exists)
 
void execute (const Catalog_Namespace::SessionInfo &session) override
 
- Public Member Functions inherited from Parser::DDLStmt
void setColumnDescriptor (ColumnDescriptor &cd, const ColumnDef *coldef)
 
- Public Member Functions inherited from Parser::Node
virtual ~Node ()
 

Private Attributes

std::unique_ptr< std::string > db_name
 
std::list< std::unique_ptr
< NameValueAssign > > 
name_value_list
 
bool if_not_exists_
 

Detailed Description

Definition at line 1806 of file ParserNode.h.

Constructor & Destructor Documentation

Parser::CreateDBStmt::CreateDBStmt ( std::string *  n,
std::list< NameValueAssign * > *  l,
const bool  if_not_exists 
)
inline

Definition at line 1808 of file ParserNode.h.

References name_value_list.

1809  : db_name(n), if_not_exists_(if_not_exists) {
1810  if (l) {
1811  for (const auto e : *l) {
1812  name_value_list.emplace_back(e);
1813  }
1814  delete l;
1815  }
1816  }
std::unique_ptr< std::string > db_name
Definition: ParserNode.h:1820
std::list< std::unique_ptr< NameValueAssign > > name_value_list
Definition: ParserNode.h:1821

Member Function Documentation

void Parser::CreateDBStmt::execute ( const Catalog_Namespace::SessionInfo session)
overridevirtual

Implements Parser::DDLStmt.

Definition at line 4453 of file ParserNode.cpp.

References Catalog_Namespace::SessionInfo::get_currentUser(), Catalog_Namespace::UserMetadata::isSuper, and Catalog_Namespace::UserMetadata::userId.

4453  {
4454  if (!session.get_currentUser().isSuper) {
4455  throw std::runtime_error(
4456  "CREATE DATABASE command can only be executed by super user.");
4457  }
4459  if (SysCatalog::instance().getMetadataForDB(*db_name, db_meta) && if_not_exists_) {
4460  return;
4461  }
4462  int ownerId = session.get_currentUser().userId;
4463  if (!name_value_list.empty()) {
4464  for (auto& p : name_value_list) {
4465  if (boost::iequals(*p->get_name(), "owner")) {
4466  if (!dynamic_cast<const StringLiteral*>(p->get_value())) {
4467  throw std::runtime_error("Owner name must be a string literal.");
4468  }
4469  const std::string* str =
4470  static_cast<const StringLiteral*>(p->get_value())->get_stringval();
4472  if (!SysCatalog::instance().getMetadataForUser(*str, user)) {
4473  throw std::runtime_error("User " + *str + " does not exist.");
4474  }
4475  ownerId = user.userId;
4476  } else {
4477  throw std::runtime_error("Invalid CREATE DATABASE option " + *p->get_name() +
4478  ". Only OWNER supported.");
4479  }
4480  }
4481  }
4482  SysCatalog::instance().createDatabase(*db_name, ownerId);
4483 }
std::unique_ptr< std::string > db_name
Definition: ParserNode.h:1820
std::list< std::unique_ptr< NameValueAssign > > name_value_list
Definition: ParserNode.h:1821
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:93
std::atomic< bool > isSuper
Definition: SysCatalog.h:85

+ Here is the call graph for this function:

Member Data Documentation

std::unique_ptr<std::string> Parser::CreateDBStmt::db_name
private

Definition at line 1820 of file ParserNode.h.

bool Parser::CreateDBStmt::if_not_exists_
private

Definition at line 1822 of file ParserNode.h.

std::list<std::unique_ptr<NameValueAssign> > Parser::CreateDBStmt::name_value_list
private

Definition at line 1821 of file ParserNode.h.

Referenced by CreateDBStmt().


The documentation for this class was generated from the following files: