OmniSciDB  a5dc49c757
 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 6859 of file ParserNode.cpp.

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

6859  {
6860  CHECK(payload.HasMember("name"));
6861  db_name_ = std::make_unique<std::string>(json_str(payload["name"]));
6862 
6863  if_not_exists_ = false;
6864  if (payload.HasMember("ifNotExists")) {
6865  if_not_exists_ = json_bool(payload["ifNotExists"]);
6866  }
6867 
6868  parse_options(payload, options_);
6869 }
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 6871 of file ParserNode.cpp.

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

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

6872  {
6873  if (read_only_mode) {
6874  throw std::runtime_error("CREATE DATABASE invalid in read only mode.");
6875  }
6876  if (!session.get_currentUser().isSuper) {
6877  throw std::runtime_error(
6878  "CREATE DATABASE command can only be executed by super user.");
6879  }
6880 
6881  const auto execute_write_lock = legacylockmgr::getExecuteWriteLock();
6882 
6884  if (SysCatalog::instance().getMetadataForDB(*db_name_, db_meta) && if_not_exists_) {
6885  return;
6886  }
6887  int ownerId = session.get_currentUser().userId;
6888  if (!options_.empty()) {
6889  for (auto& p : options_) {
6890  if (boost::iequals(*p->get_name(), "owner")) {
6891  checkStringLiteral("Owner name", p);
6892  const std::string* str =
6893  static_cast<const StringLiteral*>(p->get_value())->get_stringval();
6895  if (!SysCatalog::instance().getMetadataForUser(*str, user)) {
6896  throw std::runtime_error("User " + *str + " does not exist.");
6897  }
6898  ownerId = user.userId;
6899  } else {
6900  throw std::runtime_error("Invalid CREATE DATABASE option " + *p->get_name() +
6901  ". Only OWNER supported.");
6902  }
6903  }
6904  }
6905  SysCatalog::instance().createDatabase(*db_name_, ownerId);
6906 }
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
T & instance()
Definition: LockMgr.cpp:101
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: