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

#include <ParserNode.h>

+ Inheritance diagram for Parser::RenameDBStmt:
+ Collaboration diagram for Parser::RenameDBStmt:

Public Member Functions

 RenameDBStmt (const rapidjson::Value &payload)
 
 RenameDBStmt (std::string *database_name, std::string *new_database_name)
 
auto constgetPreviousDatabaseName ()
 
auto constgetNewDatabaseName ()
 
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 > database_name_
 
std::unique_ptr< std::string > new_database_name_
 

Detailed Description

Definition at line 1280 of file ParserNode.h.

Constructor & Destructor Documentation

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

Definition at line 4039 of file ParserNode.cpp.

References CHECK, database_name_, json_str(), and new_database_name_.

4039  {
4040  CHECK(payload.HasMember("name"));
4041  database_name_ = std::make_unique<std::string>(json_str(payload["name"]));
4042  CHECK(payload.HasMember("newName"));
4043  new_database_name_ = std::make_unique<std::string>(json_str(payload["newName"]));
4044 }
std::unique_ptr< std::string > new_database_name_
Definition: ParserNode.h:1293
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
std::unique_ptr< std::string > database_name_
Definition: ParserNode.h:1292
#define CHECK(condition)
Definition: Logger.h:209

+ Here is the call graph for this function:

Parser::RenameDBStmt::RenameDBStmt ( std::string *  database_name,
std::string *  new_database_name 
)
inline

Definition at line 1284 of file ParserNode.h.

1285  : database_name_(database_name), new_database_name_(new_database_name) {}
std::unique_ptr< std::string > new_database_name_
Definition: ParserNode.h:1293
std::unique_ptr< std::string > database_name_
Definition: ParserNode.h:1292

Member Function Documentation

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

Implements Parser::DDLStmt.

Definition at line 4046 of file ParserNode.cpp.

References database_name_, Catalog_Namespace::DBMetadata::dbOwner, legacylockmgr::ExecutorOuterLock, Catalog_Namespace::SessionInfo::get_currentUser(), legacylockmgr::LockMgr< MutexType, KeyType >::getMutex(), Catalog_Namespace::UserMetadata::isSuper, new_database_name_, and Catalog_Namespace::UserMetadata::userId.

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

4046  {
4048 
4049  // TODO: use database lock instead
4050  const auto execute_write_lock = mapd_unique_lock<mapd_shared_mutex>(
4053 
4054  if (!SysCatalog::instance().getMetadataForDB(*database_name_, db)) {
4055  throw std::runtime_error("Database " + *database_name_ + " does not exist.");
4056  }
4057 
4058  if (!session.get_currentUser().isSuper &&
4059  session.get_currentUser().userId != db.dbOwner) {
4060  throw std::runtime_error("Only a super user or the owner can rename the database.");
4061  }
4062 
4063  SysCatalog::instance().renameDatabase(*database_name_, *new_database_name_);
4064 }
std::unique_ptr< std::string > new_database_name_
Definition: ParserNode.h:1293
std::unique_ptr< std::string > database_name_
Definition: ParserNode.h:1292
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:118

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

auto const& Parser::RenameDBStmt::getNewDatabaseName ( )
inline

Definition at line 1288 of file ParserNode.h.

References new_database_name_.

1288 { return new_database_name_; }
std::unique_ptr< std::string > new_database_name_
Definition: ParserNode.h:1293
auto const& Parser::RenameDBStmt::getPreviousDatabaseName ( )
inline

Definition at line 1287 of file ParserNode.h.

References database_name_.

1287 { return database_name_; }
std::unique_ptr< std::string > database_name_
Definition: ParserNode.h:1292

Member Data Documentation

std::unique_ptr<std::string> Parser::RenameDBStmt::database_name_
private

Definition at line 1292 of file ParserNode.h.

Referenced by execute(), getPreviousDatabaseName(), and RenameDBStmt().

std::unique_ptr<std::string> Parser::RenameDBStmt::new_database_name_
private

Definition at line 1293 of file ParserNode.h.

Referenced by execute(), getNewDatabaseName(), and RenameDBStmt().


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