OmniSciDB  ca0c39ec8f
 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, bool read_only_mode) 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 1971 of file ParserNode.h.

Constructor & Destructor Documentation

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

Definition at line 6518 of file ParserNode.cpp.

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

6518  {
6519  CHECK(payload.HasMember("name"));
6520  db_name_ = std::make_unique<std::string>(json_str(payload["name"]));
6521 
6522  if_not_exists_ = false;
6523  if (payload.HasMember("ifNotExists")) {
6524  if_not_exists_ = json_bool(payload["ifNotExists"]);
6525  }
6526 
6527  parse_options(payload, options_);
6528 }
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:1989
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:1988
#define CHECK(condition)
Definition: Logger.h:222

+ 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 1975 of file ParserNode.h.

References options_.

1976  : db_name_(n), if_not_exists_(if_not_exists) {
1977  if (l) {
1978  for (const auto e : *l) {
1979  options_.emplace_back(e);
1980  }
1981  delete l;
1982  }
1983  }
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:1989
std::unique_ptr< std::string > db_name_
Definition: ParserNode.h:1988
constexpr double n
Definition: Utm.h:38

Member Function Documentation

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

Implements Parser::DDLStmt.

Definition at line 6530 of file ParserNode.cpp.

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

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

6531  {
6532  if (read_only_mode) {
6533  throw std::runtime_error("CREATE DATABASE invalid in read only mode.");
6534  }
6535  if (!session.get_currentUser().isSuper) {
6536  throw std::runtime_error(
6537  "CREATE DATABASE command can only be executed by super user.");
6538  }
6539 
6540  const auto execute_write_lock =
6544 
6546  if (SysCatalog::instance().getMetadataForDB(*db_name_, db_meta) && if_not_exists_) {
6547  return;
6548  }
6549  int ownerId = session.get_currentUser().userId;
6550  if (!options_.empty()) {
6551  for (auto& p : options_) {
6552  if (boost::iequals(*p->get_name(), "owner")) {
6553  checkStringLiteral("Owner name", p);
6554  const std::string* str =
6555  static_cast<const StringLiteral*>(p->get_value())->get_stringval();
6557  if (!SysCatalog::instance().getMetadataForUser(*str, user)) {
6558  throw std::runtime_error("User " + *str + " does not exist.");
6559  }
6560  ownerId = user.userId;
6561  } else {
6562  throw std::runtime_error("Invalid CREATE DATABASE option " + *p->get_name() +
6563  ". Only OWNER supported.");
6564  }
6565  }
6566  }
6567  SysCatalog::instance().createDatabase(*db_name_, ownerId);
6568 }
static std::shared_ptr< WrapperType< MutexType > > getMutex(const LockType lockType, const KeyType &key)
static void checkStringLiteral(const std::string &option_name, const std::unique_ptr< NameValueAssign > &p)
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:1989
std::unique_lock< T > unique_lock
std::unique_ptr< std::string > db_name_
Definition: ParserNode.h:1988
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:88
std::atomic< bool > isSuper
Definition: SysCatalog.h:107

+ 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 1988 of file ParserNode.h.

Referenced by CreateDBStmt(), and execute().

bool Parser::CreateDBStmt::if_not_exists_
private

Definition at line 1990 of file ParserNode.h.

Referenced by CreateDBStmt(), and execute().

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

Definition at line 1989 of file ParserNode.h.

Referenced by CreateDBStmt(), and execute().


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