43 std::same_as<std::remove_cv_t<T>,
float> || std::same_as<std::remove_cv_t<T>,
double> ||
68 using size_type = std::size_t;
70 size_type RowIndex()
const {
return row_index_; }
71 size_type FieldIndex()
const {
return field_index_; }
75 std::string GetString()
const;
76 int64_t GetInt64()
const;
77 int32_t GetInt32()
const;
78 double GetDouble()
const;
91 Field(detail::ResultWrapperPtr res, size_type row, size_type col)
92 : res_{std::move(res)},
98 std::int64_t GetSignedIntegerForAs()
const;
99 std::uint64_t GetUnsignedIntegerForAs()
const;
100 double GetFloatingPointForAs()
const;
101 std::string GetStringForAs()
const;
102 bool GetBoolForAs()
const;
103 Bytes GetBytesForAs()
const;
104 Date GetDateForAs()
const;
105 Time GetTimeForAs()
const;
106 Timestamp GetTimestampForAs()
const;
107 std::string GetDecimalForAs(std::size_t precision, std::size_t scale)
const;
109 detail::ResultWrapperPtr res_;
110 size_type row_index_{0};
111 size_type field_index_{0};
116 using Value = std::remove_cv_t<T>;
118 !impl::kIsOptional<Value> || !io::traits::kHasMappingDeclaration<Value>,
119 "CppToOdbc<std::optional<T>> is not supported; map T and use std::optional<T> for SQL NULL"
121 static_assert(impl::kIsFieldAsType<Value>,
"Unsupported ODBC Field::As<T>() type");
123 if constexpr (impl::kIsOptional<Value>) {
124 using Inner =
typename impl::IsOptional<Value>::ValueType;
128 return Value{As<Inner>()};
129 }
else if constexpr (!impl::kIsFieldScalar<Value> && io::traits::kHasFromOdbc<Value>) {
131 using BoundType =
typename Mapping::BoundType;
132 return Mapping::FromOdbc(As<BoundType>());
133 }
else if constexpr (std::same_as<Value,
bool>) {
134 return GetBoolForAs();
135 }
else if constexpr (std::signed_integral<Value>) {
136 const auto value = GetSignedIntegerForAs();
137 if (value <
static_cast<std::int64_t>(std::numeric_limits<Value>::lowest()) ||
138 value >
static_cast<std::int64_t>(std::numeric_limits<Value>::max()))
140 throw ResultSetError(
"ODBC integer field does not fit into the requested signed type");
142 return static_cast<Value>(value);
143 }
else if constexpr (std::unsigned_integral<Value>) {
144 const auto value = GetUnsignedIntegerForAs();
145 if (value >
static_cast<std::uint64_t>(std::numeric_limits<Value>::max())) {
146 throw ResultSetError(
"ODBC integer field does not fit into the requested unsigned type");
148 return static_cast<Value>(value);
149 }
else if constexpr (std::same_as<Value,
float>) {
150 const auto value = GetFloatingPointForAs();
151 if (value <
static_cast<
double>(std::numeric_limits<
float>::lowest()) ||
152 value >
static_cast<
double>(std::numeric_limits<
float>::max()))
154 throw ResultSetError(
"ODBC floating-point field does not fit into float");
156 return static_cast<
float>(value);
157 }
else if constexpr (std::same_as<Value,
double>) {
158 return GetFloatingPointForAs();
159 }
else if constexpr (std::same_as<Value, std::string>) {
160 return GetStringForAs();
161 }
else if constexpr (std::same_as<Value, Bytes>) {
162 return GetBytesForAs();
163 }
else if constexpr (std::same_as<Value, Date>) {
164 return GetDateForAs();
165 }
else if constexpr (std::same_as<Value, Time>) {
166 return GetTimeForAs();
167 }
else if constexpr (std::same_as<Value, Timestamp>) {
168 return GetTimestampForAs();
169 }
else if constexpr (impl::kIsDecimal<Value>) {
170 return Value{GetDecimalForAs(Value::kPrecision, Value::kScale)};