Hazelcast C++ Client
Hazelcast C++ Client Library
Loading...
Searching...
No Matches
sql_statement.h
1/*
2 * Copyright (c) 2008-2021, 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 <chrono>
19#include <cstddef>
20#include <string>
21
22#include <boost/optional/optional.hpp>
23
24#include "hazelcast/util/export.h"
25#include "hazelcast/client/serialization/pimpl/data.h"
26#include "hazelcast/client/serialization/serialization.h"
27#include "hazelcast/client/sql/sql_expected_result_type.h"
28
29namespace hazelcast {
30namespace client {
31namespace sql {
32class sql_service;
33
41class HAZELCAST_API sql_statement
42{
43public:
48 static constexpr std::chrono::milliseconds TIMEOUT_NOT_SET{ -1 };
49
54 static constexpr std::chrono::milliseconds TIMEOUT_DISABLED{ 0 };
55
57 static constexpr std::chrono::milliseconds DEFAULT_TIMEOUT =
59
61 static constexpr int32_t DEFAULT_CURSOR_BUFFER_SIZE = 4096;
62
68 sql_statement(hazelcast_client& client, std::string query);
69
74 const std::string& sql() const;
75
86 sql_statement& sql(std::string sql_string);
87
103 template<typename... Param>
104 sql_statement& set_parameters(Param... params);
105
115 template<typename Param>
116 sql_statement& add_parameter(const Param& value);
117
127
133 int32_t cursor_buffer_size() const;
134
156 sql_statement& cursor_buffer_size(int32_t size);
157
163 std::chrono::milliseconds timeout() const;
164
180 sql_statement& timeout(std::chrono::milliseconds timeout);
181
187 sql_expected_result_type expected_result_type() const;
188
195 sql_statement& expected_result_type(sql_expected_result_type type);
196
202 std::shared_ptr<std::atomic<int32_t>> partition_argument_index() const;
203
210 const boost::optional<std::string>& schema() const;
211
226 sql_statement& schema(boost::optional<std::string> schema);
227
228private:
229 using data = serialization::pimpl::data;
230 using serialization_service = serialization::pimpl::SerializationService;
231
232 sql_statement(spi::ClientContext& client_context, std::string query);
233
246
247 std::string sql_;
248 std::vector<data> serialized_parameters_;
249 int32_t cursor_buffer_size_;
250 std::chrono::milliseconds timeout_;
251 sql::sql_expected_result_type expected_result_type_;
252 boost::optional<std::string> schema_;
253 std::shared_ptr<std::atomic<int32_t>> partition_argument_index_;
254
255 serialization_service& serialization_service_;
256
258};
259
260template<typename Param>
263{
264 serialized_parameters_.emplace_back(serialization_service_.to_data(param));
265
266 return *this;
267}
268
269template<typename... Param>
272{
273 int _[] = { 0, ((void)add_parameter(params), 0)... };
274 (void)_;
275 return *this;
276}
277
278} // namespace sql
279} // namespace client
280} // namespace hazelcast
A service to execute SQL statements.
Definition sql_service.h:90
Definition of an SQL statement.
sql_statement & set_parameters(Param... params)
Sets the values for statement parameters.
static constexpr std::chrono::milliseconds TIMEOUT_DISABLED
Value for the timeout that is disabled, meaning there's no time limit to run a query.
sql_statement & add_parameter(const Param &value)
Adds a single parameter value to the end of the parameter values list.
std::shared_ptr< std::atomic< int32_t > > partition_argument_index() const
Get the partition argument index value.
Definition sql.cpp:578
static constexpr int32_t DEFAULT_CURSOR_BUFFER_SIZE
Default cursor buffer size.
const boost::optional< std::string > & schema() const
Gets the schema name.
Definition sql.cpp:552
std::chrono::milliseconds timeout() const
Gets the execution timeout in milliseconds.
Definition sql.cpp:529
sql_statement & clear_parameters()
Clears statement parameter values.
Definition sql.cpp:504
static constexpr std::chrono::milliseconds DEFAULT_TIMEOUT
Default timeout.
sql_statement(hazelcast_client &client, std::string query)
Creates a statement with the given query.
Definition sql.cpp:461
int32_t cursor_buffer_size() const
Gets the cursor buffer size (measured in the number of rows).
Definition sql.cpp:512
const std::string & sql() const
Definition sql.cpp:488
static constexpr std::chrono::milliseconds TIMEOUT_NOT_SET
Value for the timeout that is not set.
sql_statement & expected_result_type(sql_expected_result_type type)
Sets the expected result type.
sql_expected_result_type expected_result_type() const
Gets the expected result type.
Definition sql.cpp:565