OmniSciDB  04ee39c94c
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 1705 of file ParserNode.h.

Constructor & Destructor Documentation

◆ CreateDBStmt()

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

Definition at line 1707 of file ParserNode.h.

References session.

1708  : db_name(n), if_not_exists_(if_not_exists) {
1709  if (l) {
1710  for (const auto e : *l) {
1711  name_value_list.emplace_back(e);
1712  }
1713  delete l;
1714  }
1715  }
std::unique_ptr< std::string > db_name
Definition: ParserNode.h:1719
std::list< std::unique_ptr< NameValueAssign > > name_value_list
Definition: ParserNode.h:1720

Member Function Documentation

◆ execute()

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

Implements Parser::DDLStmt.

Definition at line 4388 of file ParserNode.cpp.

References Catalog_Namespace::SessionInfo::get_currentUser(), Catalog_Namespace::UserMetadata::isSuper, anonymous_namespace{DBObjectPrivilegesTest.cpp}::user, and Catalog_Namespace::UserMetadata::userId.

4388  {
4389  if (!session.get_currentUser().isSuper) {
4390  throw std::runtime_error(
4391  "CREATE DATABASE command can only be executed by super user.");
4392  }
4394  if (SysCatalog::instance().getMetadataForDB(*db_name, db_meta) && if_not_exists_) {
4395  return;
4396  }
4397  int ownerId = session.get_currentUser().userId;
4398  if (!name_value_list.empty()) {
4399  for (auto& p : name_value_list) {
4400  if (boost::iequals(*p->get_name(), "owner")) {
4401  if (!dynamic_cast<const StringLiteral*>(p->get_value())) {
4402  throw std::runtime_error("Owner name must be a string literal.");
4403  }
4404  const std::string* str =
4405  static_cast<const StringLiteral*>(p->get_value())->get_stringval();
4407  if (!SysCatalog::instance().getMetadataForUser(*str, user)) {
4408  throw std::runtime_error("User " + *str + " does not exist.");
4409  }
4410  ownerId = user.userId;
4411  } else {
4412  throw std::runtime_error("Invalid CREATE DATABASE option " + *p->get_name() +
4413  ". Only OWNER supported.");
4414  }
4415  }
4416  }
4417  SysCatalog::instance().createDatabase(*db_name, ownerId);
4418 }
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:93
std::unique_ptr< std::string > db_name
Definition: ParserNode.h:1719
std::list< std::unique_ptr< NameValueAssign > > name_value_list
Definition: ParserNode.h:1720
+ Here is the call graph for this function:

Member Data Documentation

◆ db_name

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

Definition at line 1719 of file ParserNode.h.

◆ if_not_exists_

bool Parser::CreateDBStmt::if_not_exists_
private

Definition at line 1721 of file ParserNode.h.

◆ name_value_list

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

Definition at line 1720 of file ParserNode.h.


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