OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Parser::DropTableStmt Class Reference

#include <ParserNode.h>

+ Inheritance diagram for Parser::DropTableStmt:
+ Collaboration diagram for Parser::DropTableStmt:

Public Member Functions

 DropTableStmt (std::string *tab, bool i)
 
 DropTableStmt (const rapidjson::Value &payload)
 
const std::string * get_table () const
 
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 > table_
 
bool if_exists_
 

Detailed Description

Definition at line 1209 of file ParserNode.h.

Constructor & Destructor Documentation

Parser::DropTableStmt::DropTableStmt ( std::string *  tab,
bool  i 
)
inline

Definition at line 1211 of file ParserNode.h.

1211 : table_(tab), if_exists_(i) {}
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1219
Parser::DropTableStmt::DropTableStmt ( const rapidjson::Value &  payload)

Definition at line 4869 of file ParserNode.cpp.

References CHECK, if_exists_, json_bool(), json_str(), and table_.

4869  {
4870  CHECK(payload.HasMember("tableName"));
4871  table_ = std::make_unique<std::string>(json_str(payload["tableName"]));
4872 
4873  if_exists_ = false;
4874  if (payload.HasMember("ifExists")) {
4875  if_exists_ = json_bool(payload["ifExists"]);
4876  }
4877 }
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::unique_ptr< std::string > table_
Definition: ParserNode.h:1219
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

Member Function Documentation

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

Implements Parser::DDLStmt.

Definition at line 4879 of file ParserNode.cpp.

References CHECK, Catalog_Namespace::SessionInfo::checkDBAccessPrivileges(), Executor::clearExternalCaches(), AccessPrivileges::DROP_TABLE, Catalog_Namespace::SessionInfo::getCatalog(), legacylockmgr::getExecuteReadLock(), lockmgr::TableLockMgrImpl< TableDataLockMgr >::getReadLockForTable(), lockmgr::TableLockMgrImpl< TableDataLockMgr >::getWriteLockForTable(), if_exists_, ddl_utils::TABLE, table_, TableDBObjectType, and ddl_utils::validate_table_type().

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

4880  {
4881  if (read_only_mode) {
4882  throw std::runtime_error("DROP TABLE invalid in read only mode.");
4883  }
4884  // Because we are able to acquire a unique_lock on the table descriptor to be dropped we
4885  // can get away with only using a shared_lock on the executor, as anything that will
4886  // touch the table being dropped with block, but other transactions are ok.
4887  const auto execute_read_lock = legacylockmgr::getExecuteReadLock();
4888  auto& catalog = session.getCatalog();
4889  const TableDescriptor* td{nullptr};
4890  std::unique_ptr<lockmgr::TableSchemaLockContainer<lockmgr::WriteLock>> td_with_lock;
4891  try {
4892  td_with_lock =
4893  std::make_unique<lockmgr::TableSchemaLockContainer<lockmgr::WriteLock>>(
4895  catalog, *table_, false));
4896  td = (*td_with_lock)();
4897  } catch (const std::runtime_error& e) {
4898  if (if_exists_) {
4899  return;
4900  } else {
4901  throw e;
4902  }
4903  }
4904 
4905  CHECK(td);
4906  CHECK(td_with_lock);
4907 
4908  // check access privileges
4909  if (!session.checkDBAccessPrivileges(
4911  throw std::runtime_error("Table " + *table_ +
4912  " will not be dropped. User has no proper privileges.");
4913  }
4914 
4916 
4917  {
4918  auto table_data_read_lock =
4920  Executor::clearExternalCaches(false, td, catalog.getCurrentDB().dbId);
4921  }
4922 
4923  auto table_data_write_lock =
4925  catalog.dropTable(td);
4926 }
auto getExecuteReadLock()
static WriteLock getWriteLockForTable(const Catalog_Namespace::Catalog &cat, const std::string &table_name)
Definition: LockMgrImpl.h:225
static const AccessPrivileges DROP_TABLE
Definition: DBObject.h:159
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1219
Catalog & getCatalog() const
Definition: SessionInfo.h:75
static ReadLock getReadLockForTable(Catalog_Namespace::Catalog &cat, const std::string &table_name)
Definition: LockMgrImpl.h:238
void validate_table_type(const TableDescriptor *td, const TableType expected_table_type, const std::string &command)
Definition: DdlUtils.cpp:745
#define CHECK(condition)
Definition: Logger.h:291
static void clearExternalCaches(bool for_update, const TableDescriptor *td, const int current_db_id)
Definition: Execute.h:438
bool checkDBAccessPrivileges(const DBObjectType &permissionType, const AccessPrivileges &privs, const std::string &objectName="") const
Definition: SessionInfo.cpp:24

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const std::string* Parser::DropTableStmt::get_table ( ) const
inline

Definition at line 1214 of file ParserNode.h.

References table_.

1214 { return table_.get(); }
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1219

Member Data Documentation

bool Parser::DropTableStmt::if_exists_
private

Definition at line 1220 of file ParserNode.h.

Referenced by DropTableStmt(), and execute().

std::unique_ptr<std::string> Parser::DropTableStmt::table_
private

Definition at line 1219 of file ParserNode.h.

Referenced by DropTableStmt(), execute(), and get_table().


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