sql_result.h 2.0 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 12 13 14 15 16 17
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/11/17.
//

#pragma once

#include <string>
羽飞's avatar
羽飞 已提交
18 19
#include <memory>

羽飞's avatar
羽飞 已提交
20
#include "sql/expr/tuple.h"
羽飞's avatar
羽飞 已提交
21
#include "sql/operator/physical_operator.h"
羽飞's avatar
羽飞 已提交
22

羽飞's avatar
羽飞 已提交
23 24
class Session;

羽飞's avatar
羽飞 已提交
25 26
/**
 * @brief SQL执行结果
羽飞's avatar
羽飞 已提交
27 28
 * @details 
 * 如果当前SQL生成了执行计划,那么在返回客户端时,调用执行计划返回结果。
羽飞's avatar
羽飞 已提交
29 30 31
 * 否则返回的结果就是当前SQL的执行结果,比如DDL语句,通过return_code和state_string来描述。
 * 如果出现了一些错误,也可以通过return_code和state_string来获取信息。
 */
羽飞's avatar
羽飞 已提交
32 33
class SqlResult 
{
羽飞's avatar
羽飞 已提交
34
public:
羽飞's avatar
羽飞 已提交
35
  SqlResult(Session *session);
羽飞's avatar
羽飞 已提交
36
  ~SqlResult()
L
Longda Feng 已提交
37 38 39 40 41 42 43 44
  {}

  void set_tuple_schema(const TupleSchema &schema);
  void set_return_code(RC rc)
  {
    return_code_ = rc;
  }
  void set_state_string(const std::string &state_string)
羽飞's avatar
羽飞 已提交
45
  {
L
Longda Feng 已提交
46
    state_string_ = state_string;
羽飞's avatar
羽飞 已提交
47 48
  }

49 50
  void set_operator(std::unique_ptr<PhysicalOperator> oper);
  
L
Longda Feng 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
  bool has_operator() const
  {
    return operator_ != nullptr;
  }
  const TupleSchema &tuple_schema() const
  {
    return tuple_schema_;
  }
  RC return_code() const
  {
    return return_code_;
  }
  const std::string &state_string() const
  {
    return state_string_;
  }
羽飞's avatar
羽飞 已提交
67 68 69 70 71 72

  RC open();
  RC close();
  RC next_tuple(Tuple *&tuple);

private:
羽飞's avatar
羽飞 已提交
73 74 75
  Session *session_ = nullptr; ///< 当前所属会话
  std::unique_ptr<PhysicalOperator> operator_;  ///< 执行计划
  TupleSchema tuple_schema_;   ///< 返回的表头信息。可能有也可能没有
羽飞's avatar
羽飞 已提交
76 77 78
  RC return_code_ = RC::SUCCESS;
  std::string state_string_;
};