58 explicit Statement(std::string_view query, Args&&... args)
59 :
ManagedObject{cass_statement_new_n(query.
data(), query.size(), sizeof...(args)), kDELETER}
61 cass_statement_set_consistency(*
this, CASS_CONSISTENCY_QUORUM);
62 cass_statement_set_is_idempotent(*
this, cass_true);
63 bind<Args...>(std::forward<Args>(args)...);
93 bindAt(std::size_t
const idx, Type&& value)
const
96 auto throwErrorIfNeeded = [idx](CassError rc, std::string_view label) {
98 throw std::logic_error(fmt::format(
"[{}] at idx {}: {}", label, idx, cass_error_desc(rc)));
101 auto bindBytes = [
this, idx](
auto const*
data,
size_t size) {
102 return cass_statement_bind_bytes(*
this, idx,
static_cast<cass_byte_t const*
>(
data), size);
105 using DecayedType = std::decay_t<Type>;
106 using UCharVectorType = std::vector<unsigned char>;
107 using UintTupleType = std::tuple<uint32_t, uint32_t>;
108 using UintByteTupleType = std::tuple<uint32_t, ripple::uint256>;
109 using ByteVectorType = std::vector<ripple::uint256>;
111 if constexpr (std::is_same_v<DecayedType, ripple::uint256> || std::is_same_v<DecayedType, ripple::uint192>) {
112 auto const rc = bindBytes(value.data(), value.size());
113 throwErrorIfNeeded(rc,
"Bind ripple::base_uint");
114 }
else if constexpr (std::is_same_v<DecayedType, ripple::AccountID>) {
115 auto const rc = bindBytes(value.data(), value.size());
116 throwErrorIfNeeded(rc,
"Bind ripple::AccountID");
117 }
else if constexpr (std::is_same_v<DecayedType, UCharVectorType>) {
118 auto const rc = bindBytes(value.data(), value.size());
119 throwErrorIfNeeded(rc,
"Bind vector<unsigned char>");
120 }
else if constexpr (std::is_convertible_v<DecayedType, std::string>) {
122 auto const rc = bindBytes(
reinterpret_cast<unsigned char const*
>(value.data()), value.size());
123 throwErrorIfNeeded(rc,
"Bind string (as bytes)");
124 }
else if constexpr (std::is_convertible_v<DecayedType, Text>) {
125 auto const rc = cass_statement_bind_string_n(*
this, idx, value.text.c_str(), value.text.size());
126 throwErrorIfNeeded(rc,
"Bind string (as TEXT)");
127 }
else if constexpr (std::is_same_v<DecayedType, UintTupleType> ||
128 std::is_same_v<DecayedType, UintByteTupleType>) {
129 auto const rc = cass_statement_bind_tuple(*
this, idx,
Tuple{std::forward<Type>(value)});
130 throwErrorIfNeeded(rc,
"Bind tuple<uint32, uint32> or <uint32_t, ripple::uint256>");
131 }
else if constexpr (std::is_same_v<DecayedType, ByteVectorType>) {
132 auto const rc = cass_statement_bind_collection(*
this, idx,
Collection{std::forward<Type>(value)});
133 throwErrorIfNeeded(rc,
"Bind collection");
134 }
else if constexpr (std::is_same_v<DecayedType, bool>) {
135 auto const rc = cass_statement_bind_bool(*
this, idx, value ? cass_true : cass_false);
136 throwErrorIfNeeded(rc,
"Bind bool");
137 }
else if constexpr (std::is_same_v<DecayedType, Limit>) {
138 auto const rc = cass_statement_bind_int32(*
this, idx, value.limit);
139 throwErrorIfNeeded(rc,
"Bind limit (int32)");
140 }
else if constexpr (std::is_convertible_v<DecayedType, boost::uuids::uuid>) {
141 auto const uuidStr = boost::uuids::to_string(value);
143 auto rc = cass_uuid_from_string(uuidStr.c_str(), &cassUuid);
144 throwErrorIfNeeded(rc,
"CassUuid from string");
145 rc = cass_statement_bind_uuid(*
this, idx, cassUuid);
146 throwErrorIfNeeded(rc,
"Bind boost::uuid");
148 }
else if constexpr (std::is_convertible_v<DecayedType, int64_t>) {
149 auto const rc = cass_statement_bind_int64(*
this, idx, value);
150 throwErrorIfNeeded(rc,
"Bind int64");