95 bindAt(std::size_t
const idx, Type&& value)
const
98 auto throwErrorIfNeeded = [idx](CassError rc, std::string_view label) {
100 throw std::logic_error(fmt::format(
"[{}] at idx {}: {}", label, idx, cass_error_desc(rc)));
103 auto bindBytes = [
this, idx](
auto const*
data,
size_t size) {
104 return cass_statement_bind_bytes(*
this, idx,
static_cast<cass_byte_t const*
>(
data), size);
107 using DecayedType = std::decay_t<Type>;
108 using UCharVectorType = std::vector<unsigned char>;
109 using UintTupleType = std::tuple<uint32_t, uint32_t>;
110 using UintByteTupleType = std::tuple<uint32_t, ripple::uint256>;
111 using ByteVectorType = std::vector<ripple::uint256>;
113 if constexpr (std::is_same_v<DecayedType, ripple::uint256> || std::is_same_v<DecayedType, ripple::uint192>) {
114 auto const rc = bindBytes(value.data(), value.size());
115 throwErrorIfNeeded(rc,
"Bind ripple::base_uint");
116 }
else if constexpr (std::is_same_v<DecayedType, ripple::AccountID>) {
117 auto const rc = bindBytes(value.data(), value.size());
118 throwErrorIfNeeded(rc,
"Bind ripple::AccountID");
119 }
else if constexpr (std::is_same_v<DecayedType, UCharVectorType>) {
120 auto const rc = bindBytes(value.data(), value.size());
121 throwErrorIfNeeded(rc,
"Bind vector<unsigned char>");
122 }
else if constexpr (std::is_convertible_v<DecayedType, std::string>) {
124 auto const rc = bindBytes(
reinterpret_cast<unsigned char const*
>(value.data()), value.size());
125 throwErrorIfNeeded(rc,
"Bind string (as bytes)");
126 }
else if constexpr (std::is_convertible_v<DecayedType, Text>) {
127 auto const rc = cass_statement_bind_string_n(*
this, idx, value.text.c_str(), value.text.size());
128 throwErrorIfNeeded(rc,
"Bind string (as TEXT)");
129 }
else if constexpr (std::is_same_v<DecayedType, UintTupleType> ||
130 std::is_same_v<DecayedType, UintByteTupleType>) {
131 auto const rc = cass_statement_bind_tuple(*
this, idx,
Tuple{std::forward<Type>(value)});
132 throwErrorIfNeeded(rc,
"Bind tuple<uint32, uint32> or <uint32_t, ripple::uint256>");
133 }
else if constexpr (std::is_same_v<DecayedType, ByteVectorType>) {
134 auto const rc = cass_statement_bind_collection(*
this, idx,
Collection{std::forward<Type>(value)});
135 throwErrorIfNeeded(rc,
"Bind collection");
136 }
else if constexpr (std::is_same_v<DecayedType, bool>) {
137 auto const rc = cass_statement_bind_bool(*
this, idx, value ? cass_true : cass_false);
138 throwErrorIfNeeded(rc,
"Bind bool");
139 }
else if constexpr (std::is_same_v<DecayedType, Limit>) {
140 auto const rc = cass_statement_bind_int32(*
this, idx, value.limit);
141 throwErrorIfNeeded(rc,
"Bind limit (int32)");
142 }
else if constexpr (std::is_convertible_v<DecayedType, boost::uuids::uuid>) {
143 auto const uuidStr = boost::uuids::to_string(value);
145 auto rc = cass_uuid_from_string(uuidStr.c_str(), &cassUuid);
146 throwErrorIfNeeded(rc,
"CassUuid from string");
147 rc = cass_statement_bind_uuid(*
this, idx, cassUuid);
148 throwErrorIfNeeded(rc,
"Bind boost::uuid");
150 }
else if constexpr (std::is_convertible_v<DecayedType, int64_t>) {
151 auto const rc = cass_statement_bind_int64(*
this, idx, value);
152 throwErrorIfNeeded(rc,
"Bind int64");