command_executor.cpp 2.1 KB
Newer Older
羽飞's avatar
羽飞 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
miniob is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
         http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details. */

//
// Created by Wangyunlai on 2023/4/25.
//

#include "sql/executor/command_executor.h"
羽飞's avatar
羽飞 已提交
16
#include "event/sql_event.h"
羽飞's avatar
羽飞 已提交
17 18
#include "sql/stmt/stmt.h"
#include "sql/executor/create_index_executor.h"
羽飞's avatar
羽飞 已提交
19 20 21 22 23 24
#include "sql/executor/create_table_executor.h"
#include "sql/executor/desc_table_executor.h"
#include "sql/executor/help_executor.h"
#include "sql/executor/show_tables_executor.h"
#include "sql/executor/trx_begin_executor.h"
#include "sql/executor/trx_end_executor.h"
羽飞's avatar
羽飞 已提交
25 26
#include "common/log/log.h"

羽飞's avatar
羽飞 已提交
27
RC CommandExecutor::execute(SQLStageEvent *sql_event)
羽飞's avatar
羽飞 已提交
28
{
羽飞's avatar
羽飞 已提交
29 30
  Stmt *stmt = sql_event->stmt();

羽飞's avatar
羽飞 已提交
31 32 33
  switch (stmt->type()) {
    case StmtType::CREATE_INDEX: {
      CreateIndexExecutor executor;
羽飞's avatar
羽飞 已提交
34 35 36 37 38 39
      return executor.execute(sql_event);
    } break;

    case StmtType::CREATE_TABLE: {
      CreateTableExecutor executor;
      return executor.execute(sql_event);
羽飞's avatar
羽飞 已提交
40 41
    } break;

羽飞's avatar
羽飞 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
    case StmtType::DESC_TABLE: {
      DescTableExecutor executor;
      return executor.execute(sql_event);
    }

    case StmtType::HELP: {
      HelpExecutor executor;
      return executor.execute(sql_event);
    }

    case StmtType::SHOW_TABLES: {
      ShowTablesExecutor executor;
      return executor.execute(sql_event);
    }

    case StmtType::BEGIN: {
      TrxBeginExecutor executor;
      return executor.execute(sql_event);
    }

    case StmtType::COMMIT:
    case StmtType::ROLLBACK: {
      TrxEndExecutor executor;
      return executor.execute(sql_event);
    }

    case StmtType::EXIT: {
      return RC::SUCCESS;
    }

羽飞's avatar
羽飞 已提交
72 73 74 75 76 77 78 79
    default: {
      LOG_ERROR("unknown command: %d", static_cast<int>(stmt->type()));
      return RC::UNIMPLENMENT;
    }
  }

  return RC::INTERNAL;
}