stmt.h 2.1 KB
Newer Older
羽飞's avatar
羽飞 已提交
1
/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
羽飞's avatar
羽飞 已提交
2 3 4 5 6 7 8 9 10 11
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. */

//
W
wangyunlai.wyl 已提交
12
// Created by Wangyunlai on 2022/5/22.
羽飞's avatar
羽飞 已提交
13 14
//

W
wangyunlai.wyl 已提交
15
#pragma once
羽飞's avatar
羽飞 已提交
16

羽飞's avatar
羽飞 已提交
17
#include "common/rc.h"
W
wangyunlai.wyl 已提交
18 19 20 21
#include "sql/parser/parse_defs.h"

class Db;

羽飞's avatar
羽飞 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#define DEFINE_ENUM()               \
  DEFINE_ENUM_ITEM(SELECT)          \
  DEFINE_ENUM_ITEM(INSERT)          \
  DEFINE_ENUM_ITEM(UPDATE)          \
  DEFINE_ENUM_ITEM(DELETE)          \
  DEFINE_ENUM_ITEM(CREATE_TABLE)    \
  DEFINE_ENUM_ITEM(DROP_TABLE)      \
  DEFINE_ENUM_ITEM(CREATE_INDEX)    \
  DEFINE_ENUM_ITEM(DROP_INDEX)      \
  DEFINE_ENUM_ITEM(SYNC)            \
  DEFINE_ENUM_ITEM(SHOW_TABLES)     \
  DEFINE_ENUM_ITEM(DESC_TABLE)      \
  DEFINE_ENUM_ITEM(BEGIN)           \
  DEFINE_ENUM_ITEM(COMMIT)          \
  DEFINE_ENUM_ITEM(ROLLBACK)        \
  DEFINE_ENUM_ITEM(LOAD_DATA)       \
  DEFINE_ENUM_ITEM(HELP)            \
  DEFINE_ENUM_ITEM(EXIT)            \
  DEFINE_ENUM_ITEM(EXPLAIN)         \
  DEFINE_ENUM_ITEM(PREDICATE)

enum class StmtType {
  #define DEFINE_ENUM_ITEM(name)  name,
  DEFINE_ENUM()
  #undef DEFINE_ENUM_ITEM
W
wangyunlai.wyl 已提交
47 48
};

羽飞's avatar
羽飞 已提交
49 50 51 52 53 54 55 56 57 58
inline const char *stmt_type_name(StmtType type)
{
  switch (type) {
    #define DEFINE_ENUM_ITEM(name)  case StmtType::name: return #name;
    DEFINE_ENUM()
    #undef DEFINE_ENUM_ITEM
    default: return "unkown";
  }
}

羽飞's avatar
羽飞 已提交
59
/**
羽飞's avatar
羽飞 已提交
60 61 62
 * @brief Stmt for Statement
 * @details SQL解析后的语句,再进一步解析成Stmt,使用内部的数据结构来表示。
 * 比如table_name,解析成具体的 Table对象,attr/field name解析成Field对象。
羽飞's avatar
羽飞 已提交
63 64 65
 */
class Stmt
{
W
wangyunlai.wyl 已提交
66 67 68 69 70 71 72
public:
  Stmt() = default;
  virtual ~Stmt() = default;

  virtual StmtType type() const = 0;

public:
73
  static RC create_stmt(Db *db, const Command &cmd, Stmt *&stmt);
W
wangyunlai.wyl 已提交
74 75 76

private:
};