sql_result.h 1.6 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 25 26
class Session;

class SqlResult 
{
羽飞's avatar
羽飞 已提交
27
public:
羽飞's avatar
羽飞 已提交
28
  SqlResult(Session *session);
羽飞's avatar
羽飞 已提交
29
  ~SqlResult()
L
Longda Feng 已提交
30 31 32 33 34 35 36 37
  {}

  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
羽飞 已提交
38
  {
L
Longda Feng 已提交
39
    state_string_ = state_string;
羽飞's avatar
羽飞 已提交
40 41
  }

42 43
  void set_operator(std::unique_ptr<PhysicalOperator> oper);
  
L
Longda Feng 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
  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
羽飞 已提交
60 61 62 63 64 65

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

private:
羽飞's avatar
羽飞 已提交
66
  Session *session_ = nullptr;
羽飞's avatar
羽飞 已提交
67
  std::unique_ptr<PhysicalOperator> operator_;
羽飞's avatar
羽飞 已提交
68 69 70 71
  TupleSchema tuple_schema_;
  RC return_code_ = RC::SUCCESS;
  std::string state_string_;
};