stmt.cpp 2.3 KB
Newer Older
羽飞's avatar
羽飞 已提交
1
/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
W
wangyunlai.wyl 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15
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 2022/5/22.
//

#include "common/log/log.h"
羽飞's avatar
羽飞 已提交
16
#include "sql/stmt/stmt.h"
W
wangyunlai.wyl 已提交
17 18 19
#include "sql/stmt/insert_stmt.h"
#include "sql/stmt/delete_stmt.h"
#include "sql/stmt/select_stmt.h"
羽飞's avatar
羽飞 已提交
20
#include "sql/stmt/explain_stmt.h"
羽飞's avatar
羽飞 已提交
21
#include "sql/stmt/create_index_stmt.h"
羽飞's avatar
羽飞 已提交
22 23 24 25 26 27 28
#include "sql/stmt/create_table_stmt.h"
#include "sql/stmt/desc_table_stmt.h"
#include "sql/stmt/help_stmt.h"
#include "sql/stmt/show_tables_stmt.h"
#include "sql/stmt/trx_begin_stmt.h"
#include "sql/stmt/trx_end_stmt.h"
#include "sql/stmt/exit_stmt.h"
W
wangyunlai.wyl 已提交
29

30
RC Stmt::create_stmt(Db *db, const Command &cmd, Stmt *&stmt)
W
wangyunlai.wyl 已提交
31 32 33
{
  stmt = nullptr;

34
  switch (cmd.flag) {
羽飞's avatar
羽飞 已提交
35
    case SCF_INSERT: {
36
      return InsertStmt::create(db, cmd.insertion, stmt);
W
wangyunlai.wyl 已提交
37
    }
羽飞's avatar
羽飞 已提交
38
    case SCF_DELETE: {
39
      return DeleteStmt::create(db, cmd.deletion, stmt);
W
wangyunlai.wyl 已提交
40
    }
羽飞's avatar
羽飞 已提交
41
    case SCF_SELECT: {
42
      return SelectStmt::create(db, cmd.selection, stmt);
羽飞's avatar
羽飞 已提交
43 44 45
    }

    case SCF_EXPLAIN: {
46
      return ExplainStmt::create(db, cmd.explain, stmt);
羽飞's avatar
羽飞 已提交
47
    }
羽飞's avatar
羽飞 已提交
48 49 50 51

    case SCF_CREATE_INDEX: {
      return CreateIndexStmt::create(db, cmd.create_index, stmt);
    }
羽飞's avatar
羽飞 已提交
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81

    case SCF_CREATE_TABLE: {
      return CreateTableStmt::create(db, cmd.create_table, stmt);
    }

    case SCF_DESC_TABLE: {
      return DescTableStmt::create(db, cmd.desc_table, stmt);
    }

    case SCF_HELP: {
      return HelpStmt::create(stmt);
    }

    case SCF_SHOW_TABLES: {
      return ShowTablesStmt::create(db, stmt);
    }

    case SCF_BEGIN: {
      return TrxBeginStmt::create(stmt);
    }

    case SCF_COMMIT:
    case SCF_ROLLBACK: {
      return TrxEndStmt::create(cmd.flag, stmt);
    }

    case SCF_EXIT: {
      return ExitStmt::create(stmt);
    }

羽飞's avatar
羽飞 已提交
82
    default: {
83
      LOG_INFO("Command::type %d doesn't need to create statement.", cmd.flag);
L
Longda Feng 已提交
84
    } break;
W
wangyunlai.wyl 已提交
85 86 87
  }
  return RC::UNIMPLENMENT;
}