OmniSciDB  ba1bac9284
 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 1935 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 1937 of file ParserNode.h.

References name_value_list.

1938  : db_name(n), if_not_exists_(if_not_exists) {
1939  if (l) {
1940  for (const auto e : *l) {
1941  name_value_list.emplace_back(e);
1942  }
1943  delete l;
1944  }
1945  }
std::unique_ptr< std::string > db_name
Definition: ParserNode.h:1949
std::list< std::unique_ptr< NameValueAssign > > name_value_list
Definition: ParserNode.h:1950

Member Function Documentation

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

Implements Parser::DDLStmt.

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

Referenced by omnisci.cursor.Cursor::executemany().

5632  {
5633  if (!session.get_currentUser().isSuper) {
5634  throw std::runtime_error(
5635  "CREATE DATABASE command can only be executed by super user.");
5636  }
5637 
5638  const auto execute_write_lock = mapd_unique_lock<mapd_shared_mutex>(
5641 
5643  if (SysCatalog::instance().getMetadataForDB(*db_name, db_meta) && if_not_exists_) {
5644  return;
5645  }
5646  int ownerId = session.get_currentUser().userId;
5647  if (!name_value_list.empty()) {
5648  for (auto& p : name_value_list) {
5649  if (boost::iequals(*p->get_name(), "owner")) {
5650  checkStringLiteral("Owner name", p);
5651  const std::string* str =
5652  static_cast<const StringLiteral*>(p->get_value())->get_stringval();
5654  if (!SysCatalog::instance().getMetadataForUser(*str, user)) {
5655  throw std::runtime_error("User " + *str + " does not exist.");
5656  }
5657  ownerId = user.userId;
5658  } else {
5659  throw std::runtime_error("Invalid CREATE DATABASE option " + *p->get_name() +
5660  ". Only OWNER supported.");
5661  }
5662  }
5663  }
5664  SysCatalog::instance().createDatabase(*db_name, ownerId);
5665 }
static void checkStringLiteral(const std::string &option_name, const std::unique_ptr< NameValueAssign > &p)
std::unique_ptr< std::string > db_name
Definition: ParserNode.h:1949
std::list< std::unique_ptr< NameValueAssign > > name_value_list
Definition: ParserNode.h:1950
static std::shared_ptr< MutexType > getMutex(const LockType lockType, const KeyType &key)
Definition: LegacyLockMgr.h:51
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:73
std::atomic< bool > isSuper
Definition: SysCatalog.h:99

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

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

Definition at line 1951 of file ParserNode.h.

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

Definition at line 1950 of file ParserNode.h.

Referenced by CreateDBStmt().


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