OmniSciDB  0fdbebe030
 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 1866 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 1868 of file ParserNode.h.

References name_value_list.

1869  : db_name(n), if_not_exists_(if_not_exists) {
1870  if (l) {
1871  for (const auto e : *l) {
1872  name_value_list.emplace_back(e);
1873  }
1874  delete l;
1875  }
1876  }
std::unique_ptr< std::string > db_name
Definition: ParserNode.h:1880
std::list< std::unique_ptr< NameValueAssign > > name_value_list
Definition: ParserNode.h:1881

Member Function Documentation

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

Implements Parser::DDLStmt.

Definition at line 4483 of file ParserNode.cpp.

References Parser::checkStringLiteral(), legacylockmgr::ExecutorOuterLock, Catalog_Namespace::SessionInfo::get_currentUser(), legacylockmgr::LockMgr< MutexType, KeyType >::getMutex(), Catalog_Namespace::UserMetadata::isSuper, and Catalog_Namespace::UserMetadata::userId.

4483  {
4484  if (!session.get_currentUser().isSuper) {
4485  throw std::runtime_error(
4486  "CREATE DATABASE command can only be executed by super user.");
4487  }
4488 
4489  const auto execute_write_lock = mapd_unique_lock<mapd_shared_mutex>(
4492 
4494  if (SysCatalog::instance().getMetadataForDB(*db_name, db_meta) && if_not_exists_) {
4495  return;
4496  }
4497  int ownerId = session.get_currentUser().userId;
4498  if (!name_value_list.empty()) {
4499  for (auto& p : name_value_list) {
4500  if (boost::iequals(*p->get_name(), "owner")) {
4501  checkStringLiteral("Owner name", p);
4502  const std::string* str =
4503  static_cast<const StringLiteral*>(p->get_value())->get_stringval();
4505  if (!SysCatalog::instance().getMetadataForUser(*str, user)) {
4506  throw std::runtime_error("User " + *str + " does not exist.");
4507  }
4508  ownerId = user.userId;
4509  } else {
4510  throw std::runtime_error("Invalid CREATE DATABASE option " + *p->get_name() +
4511  ". Only OWNER supported.");
4512  }
4513  }
4514  }
4515  SysCatalog::instance().createDatabase(*db_name, ownerId);
4516 }
static void checkStringLiteral(const std::string &option_name, const std::unique_ptr< NameValueAssign > &p)
std::unique_ptr< std::string > db_name
Definition: ParserNode.h:1880
std::list< std::unique_ptr< NameValueAssign > > name_value_list
Definition: ParserNode.h:1881
static std::shared_ptr< MutexType > getMutex(const LockType lockType, const KeyType &key)
Definition: LegacyLockMgr.h:51
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:79
std::atomic< bool > isSuper
Definition: SysCatalog.h:96

+ Here is the call graph for this function:

Member Data Documentation

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

Definition at line 1880 of file ParserNode.h.

bool Parser::CreateDBStmt::if_not_exists_
private

Definition at line 1882 of file ParserNode.h.

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

Definition at line 1881 of file ParserNode.h.

Referenced by CreateDBStmt().


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