OmniSciDB  72c90bc290
 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 1914 of file ParserNode.h.

Constructor & Destructor Documentation

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

Definition at line 6838 of file ParserNode.cpp.

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

6838  {
6839  CHECK(payload.HasMember("name"));
6840  db_name_ = std::make_unique<std::string>(json_str(payload["name"]));
6841 
6842  if_not_exists_ = false;
6843  if (payload.HasMember("ifNotExists")) {
6844  if_not_exists_ = json_bool(payload["ifNotExists"]);
6845  }
6846 
6847  parse_options(payload, options_);
6848 }
const bool json_bool(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:51
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:46
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:1932
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:1931
#define CHECK(condition)
Definition: Logger.h:291

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

References options_.

1919  : db_name_(n), if_not_exists_(if_not_exists) {
1920  if (l) {
1921  for (const auto e : *l) {
1922  options_.emplace_back(e);
1923  }
1924  delete l;
1925  }
1926  }
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:1932
std::unique_ptr< std::string > db_name_
Definition: ParserNode.h:1931
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 6850 of file ParserNode.cpp.

References Parser::checkStringLiteral(), db_name_, Catalog_Namespace::SessionInfo::get_currentUser(), legacylockmgr::getExecuteWriteLock(), if_not_exists_, Catalog_Namespace::UserMetadata::isSuper, options_, and Catalog_Namespace::UserMetadata::userId.

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

6851  {
6852  if (read_only_mode) {
6853  throw std::runtime_error("CREATE DATABASE invalid in read only mode.");
6854  }
6855  if (!session.get_currentUser().isSuper) {
6856  throw std::runtime_error(
6857  "CREATE DATABASE command can only be executed by super user.");
6858  }
6859 
6860  const auto execute_write_lock = legacylockmgr::getExecuteWriteLock();
6861 
6863  if (SysCatalog::instance().getMetadataForDB(*db_name_, db_meta) && if_not_exists_) {
6864  return;
6865  }
6866  int ownerId = session.get_currentUser().userId;
6867  if (!options_.empty()) {
6868  for (auto& p : options_) {
6869  if (boost::iequals(*p->get_name(), "owner")) {
6870  checkStringLiteral("Owner name", p);
6871  const std::string* str =
6872  static_cast<const StringLiteral*>(p->get_value())->get_stringval();
6874  if (!SysCatalog::instance().getMetadataForUser(*str, user)) {
6875  throw std::runtime_error("User " + *str + " does not exist.");
6876  }
6877  ownerId = user.userId;
6878  } else {
6879  throw std::runtime_error("Invalid CREATE DATABASE option " + *p->get_name() +
6880  ". Only OWNER supported.");
6881  }
6882  }
6883  }
6884  SysCatalog::instance().createDatabase(*db_name_, ownerId);
6885 }
static void checkStringLiteral(const std::string &option_name, const std::unique_ptr< NameValueAssign > &p)
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:1932
std::unique_ptr< std::string > db_name_
Definition: ParserNode.h:1931
auto getExecuteWriteLock()
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 1931 of file ParserNode.h.

Referenced by CreateDBStmt(), and execute().

bool Parser::CreateDBStmt::if_not_exists_
private

Definition at line 1933 of file ParserNode.h.

Referenced by CreateDBStmt(), and execute().

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

Definition at line 1932 of file ParserNode.h.

Referenced by CreateDBStmt(), and execute().


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