17#include "RelationalAccess/ICursor.h"
19#include "CoralBase/Attribute.h"
20#include "CoralBase/AttributeList.h"
21#include "CoralBase/AttributeSpecification.h"
27 ,
const std::string& tableName)
32 m_values =
new coral::AttributeList(attList.specification(),
false);
33 m_values->fastCopyData (attList);
35 for(
unsigned int i=0; i<m_values->size(); i++) {
36 std::string key = (*m_values)[i].specification().name();
49 std::string name =std::format(
"{}.{}",
m_tableName, fieldName);
50 FieldName2ListIndex::const_iterator it =
m_name2Index.find(name);
52 throw std::runtime_error(std::format(
"Wrong name for the field {}", name));
55 const coral::AttributeList& values = *m_values;
56 const auto &itr = values[it->second];
57 if(itr.specification().type()==
typeid(T)) {
60 throw std::runtime_error(std::format(
"Field {} is NOT a type of {}", fieldName,
typeid(T).name()));
64RDBRecord::FieldName2ListIndex::const_iterator
RDBRecord::getItr(std::string_view fieldName)
const
66 const std::string name = std::format(
"{}.{}",
m_tableName, fieldName);
67 FieldName2ListIndex::const_iterator it =
m_name2Index.find(name);
69 throw std::runtime_error(
"Wrong name for the field " + name);
76 const std::string name =std::format(
"{}.{}_{}",
m_tableName, fieldName,
index);
77 FieldName2ListIndex::const_iterator it =
m_name2Index.find(name);
79 throw std::runtime_error(std::format(
"Wrong name for the array field {}.{} or index={} is out of range.",
m_tableName,fieldName,
index));
87 auto it =
getItr(fieldName);
89 const coral::AttributeList& values = *m_values;
90 return values[it->second].isNull();
95 auto it =
getItr(fieldName);
96 const coral::AttributeList& values = *m_values;
97 const auto& item = values[it->second];
98 if(item.specification().type()==
typeid(
int)) {
99 return item.data<
int>();
101 else if(item.specification().type()==
typeid(
long)) {
102 return (
int)item.data<
long>();
105 throw std::runtime_error( std::format(
"Field {} is NOT of integer type", fieldName));
111 auto it =
getItr(fieldName);
112 const coral::AttributeList& values = *m_values;
113 const auto& item = values[it->second];
114 if(item.specification().type()==
typeid(
long)) {
115 return item.data<
long>();
117 else if(item.specification().type()==
typeid(
int)) {
118 return (
long)item.data<
int>();
120 else if(item.specification().type()==
typeid(
long long)) {
121 return (
long)item.data<
long long>();
124 throw std::runtime_error( std::format(
"Field {} is NOT of long type",fieldName));
146 const coral::AttributeList& values = *m_values;
147 const auto &item = values[it->second];
148 if(item.specification().type()==
typeid(
int)) {
149 return item.data<
int>();
151 else if(item.specification().type()==
typeid(
long)) {
152 return (
int)item.data<
long>();
155 throw std::runtime_error( std::format(
"Field {} is NOT of integer type", fieldName));
162 const coral::AttributeList& values = *m_values;
163 const auto &item = values[it->second];
164 if(item.specification().type()==
typeid(
long)) {
165 return item.data<
long>();
167 else if(item.specification().type()==
typeid(
int)) {
168 return (
long)item.data<
int>();
171 throw std::runtime_error( std::format(
"Field {} is NOT of long type", fieldName));
178 const coral::AttributeList& values = *m_values;
179 const auto &item = values[it->second];
180 if(item.specification().type()==
typeid(
double)) {
181 return item.data<
double>();
184 throw std::runtime_error( std::format(
"Field {} is NOT of double type",fieldName));
191 const coral::AttributeList& values = *m_values;
192 const auto &item = values[it->second];
193 if(item.specification().type()==
typeid(
float)) {
194 return item.data<
float>();
197 throw std::runtime_error( std::format(
"Field {} is NOT of float type", fieldName));
204 const coral::AttributeList& values = *m_values;
205 const auto &item = values[it->second];
206 if(item.specification().type()==
typeid(std::string)) {
207 return item.data<std::string>();
210 throw std::runtime_error( std::format(
"Field {} is NOT of string type", fieldName));
216 const coral::AttributeList& myAttList = *m_values;
217 const coral::AttributeList& rhsAttList = *rhs.m_values;
219 if(myAttList.size()!=rhsAttList.size())
return true;
221 for(
size_t i(0); i<myAttList.size(); ++i) {
222 const coral::Attribute& myAtt = myAttList[i];
223 const std::string name = myAtt.specification().name();
225 for(
size_t j(0); j<rhsAttList.size(); ++j) {
226 const coral::Attribute& rhsAtt = rhsAttList[j];
227 if(rhsAtt.specification().name()==name) {
243 m_values->toOutputStream(os);
Definition of RDBRecord class.
long getLong(std::string_view fieldName) const override
Get long field value.
bool operator!=(const RDBRecord &rhs) const
RDBRecord(const RDBRecord &)=delete
int getInt(std::string_view fieldName) const override
Get int field value.
float getFloat(std::string_view fieldName) const override
Get float field value.
const T & getGeneric(std::string_view fieldName) const
std::ostream & toOutputStream(std::ostream &os) const
RDBRecord()
Empty private constructor.
~RDBRecord() override
Destructor.
virtual const std::string & getString(std::string_view string_view) const override
Get string field value.
bool isFieldNull(std::string_view fieldName) const override
Check if the field value is NULL.
FieldName2ListIndex::const_iterator getItr(std::string_view fieldName) const
double getDouble(std::string_view fieldName) const override
Get double field value.
FieldName2ListIndex m_name2Index
bool exists(const std::string &filename)
does a file exist