OmniSciDB  06b3bd477c
 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 1876 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 1878 of file ParserNode.h.

References name_value_list.

1879  : db_name(n), if_not_exists_(if_not_exists) {
1880  if (l) {
1881  for (const auto e : *l) {
1882  name_value_list.emplace_back(e);
1883  }
1884  delete l;
1885  }
1886  }
std::unique_ptr< std::string > db_name
Definition: ParserNode.h:1890
std::list< std::unique_ptr< NameValueAssign > > name_value_list
Definition: ParserNode.h:1891

Member Function Documentation

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

Implements Parser::DDLStmt.

Definition at line 4687 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.

4687  {
4688  if (!session.get_currentUser().isSuper) {
4689  throw std::runtime_error(
4690  "CREATE DATABASE command can only be executed by super user.");
4691  }
4692 
4693  const auto execute_write_lock = mapd_unique_lock<mapd_shared_mutex>(
4696 
4698  if (SysCatalog::instance().getMetadataForDB(*db_name, db_meta) && if_not_exists_) {
4699  return;
4700  }
4701  int ownerId = session.get_currentUser().userId;
4702  if (!name_value_list.empty()) {
4703  for (auto& p : name_value_list) {
4704  if (boost::iequals(*p->get_name(), "owner")) {
4705  checkStringLiteral("Owner name", p);
4706  const std::string* str =
4707  static_cast<const StringLiteral*>(p->get_value())->get_stringval();
4709  if (!SysCatalog::instance().getMetadataForUser(*str, user)) {
4710  throw std::runtime_error("User " + *str + " does not exist.");
4711  }
4712  ownerId = user.userId;
4713  } else {
4714  throw std::runtime_error("Invalid CREATE DATABASE option " + *p->get_name() +
4715  ". Only OWNER supported.");
4716  }
4717  }
4718  }
4719  SysCatalog::instance().createDatabase(*db_name, ownerId);
4720 }
static void checkStringLiteral(const std::string &option_name, const std::unique_ptr< NameValueAssign > &p)
std::unique_ptr< std::string > db_name
Definition: ParserNode.h:1890
std::list< std::unique_ptr< NameValueAssign > > name_value_list
Definition: ParserNode.h:1891
static std::shared_ptr< MutexType > getMutex(const LockType lockType, const KeyType &key)
Definition: LegacyLockMgr.h:51
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:68
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 1890 of file ParserNode.h.

bool Parser::CreateDBStmt::if_not_exists_
private

Definition at line 1892 of file ParserNode.h.

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

Definition at line 1891 of file ParserNode.h.

Referenced by CreateDBStmt().


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