14#include "boost/io/ios_state.hpp"
33 if(
m_def->find(field)==
m_def->end())
throw std::runtime_error( std::format(
"Wrong name for the field {}",field));
41 return std::get<int>(recIt->second);
50 return (
long)
getInt(field);
57 return std::get<double>(recIt->second);
73 return std::get<std::string>(recIt->second);
76 throw std::runtime_error(
"Unexpected error in SqliteRecord::getString()");
106 auto [it,result] =
m_record.emplace(std::string{field}, std::move(value));
107 if(!result)
throw std::runtime_error(std::format(
"Unexpected error when adding new value for the field {}. Duplicate field name?", field));
112 boost::io::ios_all_saver saver (std::cout);
114 for(
const auto& [colName,colType] : *
m_def) {
121 auto recIt =
m_record.find(colName);
122 bool fieldNull = (recIt==
m_record.end());
123 std::cout <<
"[" << colName <<
" (";
126 std::cout <<
"int) : " << (fieldNull?
"NULL" : std::to_string(std::get<int>(recIt->second))) <<
"]";
129 std::cout <<
"long) : " << (fieldNull?
"NULL" : std::to_string(std::get<long>(recIt->second))) <<
"]";
132 std::cout <<
"float) : ";
137 std::cout << std::setprecision(10) << std::get<float>(recIt->second) <<
"]";
141 std::cout <<
"double) : ";
146 std::cout << std::setprecision(10) << std::get<double>(recIt->second) <<
"]";
150 std::cout <<
"string) : " << (fieldNull?
"NULL" : (
"\"" + std::get<std::string>(recIt->second)) +
"\"") <<
"]";
153 std::cout <<
"ERROR) : ]";
156 std::cout << std::endl;
164 throw std::runtime_error( std::format(
"handleError: Wrong name for the field {}",field));
166 throw std::runtime_error( std::format(
"handleError: Wrong data type requested for the field {}",field));
168 throw std::runtime_error( std::format(
"handleError: {} is NULL", field));
Declaration of the SqliteRecord class.
std::shared_ptr< SqliteInpDef > SqliteInpDef_ptr
std::variant< int, long, float, double, std::string > SqliteInp
bool isFieldNull(std::string_view field) const override
Check if the field value is NULL.
void handleError(std::string_view field, FieldCheckCode checkCode) const
float getFloat(std::string_view field) const override
Get float field value.
FieldCheckResult checkField(std::string_view field, SqliteInpType fieldType) const
void addValue(std::string_view field, SqliteInp value)
void dump() const
Dump to cout.
int getInt(std::string_view field) const override
Get int field value.
virtual const std::string & getString(std::string_view field) const override
Get string field value.
double getDouble(std::string_view field) const override
Get double field value.
long getLong(std::string_view field) const override
Get long field value.
~SqliteRecord() override
Destructor.