1 /* 2 Copyright (c) DataStax, Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 #ifndef DATASTAX_INTERNAL_RESULT_RESPONSE_HPP 18 #define DATASTAX_INTERNAL_RESULT_RESPONSE_HPP 19 20 #include "constants.hpp" 21 #include "data_type.hpp" 22 #include "macros.hpp" 23 #include "response.hpp" 24 #include "result_metadata.hpp" 25 #include "row.hpp" 26 #include "string_ref.hpp" 27 #include "vector.hpp" 28 29 namespace datastax { namespace internal { namespace core { 30 31 class ResultIterator; 32 33 class ResultResponse : public Response { 34 public: 35 typedef SharedRefPtr<ResultResponse> Ptr; 36 typedef SharedRefPtr<const ResultResponse> ConstPtr; 37 typedef Vector<size_t> PKIndexVec; 38 ResultResponse()39 ResultResponse() 40 : Response(CQL_OPCODE_RESULT) 41 , kind_(CASS_RESULT_KIND_VOID) 42 , has_more_pages_(false) 43 , row_count_(0) { 44 first_row_.set_result(this); 45 } 46 kind() const47 int32_t kind() const { return kind_; } 48 protocol_version() const49 ProtocolVersion protocol_version() const { return protocol_version_; } 50 has_more_pages() const51 bool has_more_pages() const { return has_more_pages_; } 52 column_count() const53 int32_t column_count() const { return (metadata_ ? metadata_->column_count() : 0); } 54 no_metadata() const55 bool no_metadata() const { return !metadata_; } 56 metadata() const57 const ResultMetadata::Ptr& metadata() const { return metadata_; } 58 59 void set_metadata(const ResultMetadata::Ptr& metadata); 60 result_metadata() const61 const ResultMetadata::Ptr& result_metadata() const { return result_metadata_; } 62 paging_state() const63 StringRef paging_state() const { return paging_state_; } prepared_id() const64 StringRef prepared_id() const { return prepared_id_; } result_metadata_id() const65 StringRef result_metadata_id() const { return result_metadata_id_; } keyspace() const66 StringRef keyspace() const { return keyspace_; } table() const67 StringRef table() const { return table_; } 68 quoted_keyspace() const69 String quoted_keyspace() const { 70 String temp(keyspace_.to_string()); 71 return escape_id(temp); 72 } 73 metadata_changed()74 bool metadata_changed() { return new_metadata_id_.size() > 0; } new_metadata_id() const75 StringRef new_metadata_id() const { return new_metadata_id_; } 76 row_decoder() const77 const Decoder& row_decoder() const { return row_decoder_; } 78 row_count() const79 int32_t row_count() const { return row_count_; } 80 first_row() const81 const Row& first_row() const { return first_row_; } 82 pk_indices() const83 const PKIndexVec& pk_indices() const { return pk_indices_; } 84 85 virtual bool decode(Decoder& decoder); 86 87 private: 88 bool decode_metadata(Decoder& decoder, ResultMetadata::Ptr* metadata, 89 bool has_pk_indices = false); 90 91 bool decode_first_row(); 92 93 bool decode_rows(Decoder& decoder); 94 95 bool decode_set_keyspace(Decoder& decoder); 96 97 bool decode_prepared(Decoder& decoder); 98 99 bool decode_schema_change(Decoder& decoder); 100 101 private: 102 int32_t kind_; 103 ProtocolVersion protocol_version_; 104 bool has_more_pages_; // row data 105 ResultMetadata::Ptr metadata_; 106 ResultMetadata::Ptr result_metadata_; 107 StringRef paging_state_; // row paging 108 StringRef prepared_id_; // prepared result 109 StringRef result_metadata_id_; // prepared result, protocol v5/DSEv2 110 StringRef change_; // schema change 111 StringRef keyspace_; // rows, set keyspace, and schema change 112 StringRef table_; // rows, and schema change 113 StringRef new_metadata_id_; // rows result, protocol v5/DSEv2 114 int32_t row_count_; 115 Decoder row_decoder_; 116 Row first_row_; 117 PKIndexVec pk_indices_; 118 119 private: 120 DISALLOW_COPY_AND_ASSIGN(ResultResponse); 121 }; 122 123 }}} // namespace datastax::internal::core 124 125 EXTERNAL_TYPE(datastax::internal::core::ResultResponse, CassResult) 126 127 #endif 128