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

#include <ParserNode.h>

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

Public Member Functions

 CreateDBStmt (const rapidjson::Value &payload)
 
 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 > > 
options_
 
bool if_not_exists_
 

Detailed Description

Definition at line 1930 of file ParserNode.h.

Constructor & Destructor Documentation

Parser::CreateDBStmt::CreateDBStmt ( const rapidjson::Value &  payload)

Definition at line 5981 of file ParserNode.cpp.

References CHECK, json_bool(), json_str(), and Parser::anonymous_namespace{ParserNode.cpp}::parse_options().

5981  {
5982  CHECK(payload.HasMember("name"));
5983  db_name_ = std::make_unique<std::string>(json_str(payload["name"]));
5984 
5985  if_not_exists_ = false;
5986  if (payload.HasMember("ifNotExists")) {
5987  if_not_exists_ = json_bool(payload["ifNotExists"]);
5988  }
5989 
5990  parse_options(payload, options_);
5991 }
const bool json_bool(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:49
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:1947
void parse_options(const rapidjson::Value &payload, std::list< std::unique_ptr< NameValueAssign >> &nameValueList, bool stringToNull=false, bool stringToInteger=false)
std::unique_ptr< std::string > db_name_
Definition: ParserNode.h:1946
#define CHECK(condition)
Definition: Logger.h:209

+ Here is the call graph for this function:

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

Definition at line 1934 of file ParserNode.h.

References options_.

1935  : db_name_(n), if_not_exists_(if_not_exists) {
1936  if (l) {
1937  for (const auto e : *l) {
1938  options_.emplace_back(e);
1939  }
1940  delete l;
1941  }
1942  }
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:1947
std::unique_ptr< std::string > db_name_
Definition: ParserNode.h:1946
constexpr double n
Definition: Utm.h:40

Member Function Documentation

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

Implements Parser::DDLStmt.

Definition at line 5993 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().

5993  {
5994  if (!session.get_currentUser().isSuper) {
5995  throw std::runtime_error(
5996  "CREATE DATABASE command can only be executed by super user.");
5997  }
5998 
5999  const auto execute_write_lock = mapd_unique_lock<mapd_shared_mutex>(
6002 
6004  if (SysCatalog::instance().getMetadataForDB(*db_name_, db_meta) && if_not_exists_) {
6005  return;
6006  }
6007  int ownerId = session.get_currentUser().userId;
6008  if (!options_.empty()) {
6009  for (auto& p : options_) {
6010  if (boost::iequals(*p->get_name(), "owner")) {
6011  checkStringLiteral("Owner name", p);
6012  const std::string* str =
6013  static_cast<const StringLiteral*>(p->get_value())->get_stringval();
6015  if (!SysCatalog::instance().getMetadataForUser(*str, user)) {
6016  throw std::runtime_error("User " + *str + " does not exist.");
6017  }
6018  ownerId = user.userId;
6019  } else {
6020  throw std::runtime_error("Invalid CREATE DATABASE option " + *p->get_name() +
6021  ". Only OWNER supported.");
6022  }
6023  }
6024  }
6025  SysCatalog::instance().createDatabase(*db_name_, ownerId);
6026 }
static void checkStringLiteral(const std::string &option_name, const std::unique_ptr< NameValueAssign > &p)
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:1947
static std::shared_ptr< MutexType > getMutex(const LockType lockType, const KeyType &key)
Definition: LegacyLockMgr.h:51
std::unique_ptr< std::string > db_name_
Definition: ParserNode.h:1946
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:73
std::atomic< bool > isSuper
Definition: SysCatalog.h:118

+ 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

Definition at line 1946 of file ParserNode.h.

bool Parser::CreateDBStmt::if_not_exists_
private

Definition at line 1948 of file ParserNode.h.

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

Definition at line 1947 of file ParserNode.h.

Referenced by CreateDBStmt().


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