stmt.h 2.3 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
/**
 * @brief Statement SQL语句解析后通过Resolver转换成Stmt
 * @defgroup Statement
 * @file stmt.h
 */

/**
 * @brief Statement的类型
 * 
 */
羽飞's avatar
羽飞 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
#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)         \
羽飞's avatar
羽飞 已提交
51 52
  DEFINE_ENUM_ITEM(PREDICATE)       \
  DEFINE_ENUM_ITEM(SET_VARIABLE)
羽飞's avatar
羽飞 已提交
53 54 55 56 57

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

羽飞's avatar
羽飞 已提交
60 61 62 63 64 65 66 67 68 69
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
羽飞 已提交
70
/**
羽飞's avatar
羽飞 已提交
71
 * @brief Stmt for Statement
羽飞's avatar
羽飞 已提交
72
 * @ingroup Statement
羽飞's avatar
羽飞 已提交
73 74
 * @details SQL解析后的语句,再进一步解析成Stmt,使用内部的数据结构来表示。
 * 比如table_name,解析成具体的 Table对象,attr/field name解析成Field对象。
羽飞's avatar
羽飞 已提交
75 76 77
 */
class Stmt
{
W
wangyunlai.wyl 已提交
78 79 80 81 82 83 84
public:
  Stmt() = default;
  virtual ~Stmt() = default;

  virtual StmtType type() const = 0;

public:
85
  static RC create_stmt(Db *db, const Command &cmd, Stmt *&stmt);
W
wangyunlai.wyl 已提交
86 87 88

private:
};