Hazelcast C++ Client
Hazelcast C++ Client Library
Loading...
Searching...
No Matches
sql_service.h
1/*
2 * Copyright (c) 2008-2025, Hazelcast, Inc. All Rights Reserved.
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#pragma once
17
18#include "hazelcast/util/export.h"
19#include "hazelcast/client/sql/sql_result.h"
20#include "hazelcast/client/sql/sql_statement.h"
21#include "hazelcast/client/sql/hazelcast_sql_exception.h"
22#include "hazelcast/client/sql/impl/read_optimized_lru_cache.h"
23
24#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
25#pragma warning(push)
26#pragma warning(disable : 4251) // for dll export
27#endif
28
29namespace hazelcast {
30namespace client {
31namespace impl {
32class hazelcast_client_instance_impl;
33}
35namespace sql {
36
89class HAZELCAST_API sql_service
90{
91public:
110 template<typename... Params>
111 boost::future<std::shared_ptr<sql_result>> execute(const std::string& query,
112 const Params&... params)
113 {
114 sql_statement s{ client_context_, query };
115 int _[] = { 0, (s.add_parameter(params), 0)... };
116 (void)_;
117 return execute(s);
118 }
119
128 boost::future<std::shared_ptr<sql_result>> execute(
129 const sql_statement& statement);
130
131 std::shared_ptr<impl::read_optimized_lru_cache<std::string, int32_t>>
132 partition_argument_index_cache_;
133
134private:
135 friend client::impl::hazelcast_client_instance_impl;
136 friend sql_result;
137
138 client::spi::ClientContext& client_context_;
139
140 bool is_smart_routing_;
141
142 struct sql_execute_response_parameters
143 {
144 int64_t update_count;
145 std::shared_ptr<sql_row_metadata> row_metadata;
146 std::shared_ptr<sql_page> first_page;
147 boost::optional<impl::sql_error> error;
148 bool is_infinite_rows = false;
149 bool is_infinite_rows_exist = false;
150 int32_t partition_argument_index = -1;
151 bool is_partition_argument_index_exists = false;
152 };
153
154 struct sql_fetch_response_parameters
155 {
156 boost::optional<std::shared_ptr<sql_page>> page;
157 boost::optional<impl::sql_error> error;
158 };
159
160 explicit sql_service(client::spi::ClientContext& context);
161
162 std::shared_ptr<connection::Connection> query_connection();
163 std::shared_ptr<connection::Connection> query_connection(
164 int32_t partition_id);
165
166 boost::optional<int32_t> extract_partition_id(
167 const sql_statement& statement,
168 const int32_t arg_index) const;
169
170 void rethrow(const std::exception& exc_ptr);
171 void rethrow(const std::exception& cause_ptr,
172 const std::shared_ptr<connection::Connection>& connection);
173
174 boost::uuids::uuid client_id();
175
176 std::shared_ptr<sql_result> handle_execute_response(
177 const std::string& sql_query,
178 const int32_t original_partition_argument_index,
179 protocol::ClientMessage& msg,
180 std::shared_ptr<connection::Connection> connection,
181 impl::query_id id,
182 int32_t cursor_buffer_size,
183 std::weak_ptr<std::atomic<int32_t>> statement_par_arg_index_ptr);
184
185 static sql_execute_response_parameters decode_execute_response(
186 protocol::ClientMessage& msg);
187
188 impl::query_id create_query_id(
189 const std::shared_ptr<connection::Connection>& query_conn);
190
191 boost::future<std::shared_ptr<sql_page>> fetch_page(
192 const impl::query_id& q_id,
193 int32_t cursor_buffer_size,
194 const std::shared_ptr<connection::Connection>& connection);
195
196 static sql_fetch_response_parameters decode_fetch_response(
197 protocol::ClientMessage message);
198
199 static void handle_fetch_response_error(
200 boost::optional<impl::sql_error> error);
201
208 boost::future<void> close(
209 const std::shared_ptr<connection::Connection>& connection,
210 impl::query_id id);
211};
212} // namespace sql
213} // namespace client
214} // namespace hazelcast
215#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
216#pragma warning(pop)
217#endif
boost::future< std::shared_ptr< sql_result > > execute(const std::string &query, const Params &... params)
Convenient method to execute a distributed query with the given parameter values.
Definition of an SQL statement.
sql_statement & add_parameter(const Param &value)
Adds a single parameter value to the end of the parameter values list.