SqliteRecord is one record in the SqliteRecordset object.
More...
#include <SqliteRecord.h>
|
| | SqliteRecord (SqliteInpDef_ptr def) |
| | SqliteRecord ()=delete |
| | SqliteRecord (const SqliteRecord &)=delete |
| SqliteRecord & | operator= (const SqliteRecord &)=delete |
| | ~SqliteRecord () override |
| | Destructor.
|
| bool | isFieldNull (const std::string &field) const override |
| | Check if the field value is NULL.
|
| int | getInt (const std::string &field) const override |
| | Get int field value.
|
| long | getLong (const std::string &field) const override |
| | Get long field value.
|
| double | getDouble (const std::string &field) const override |
| | Get double field value.
|
| float | getFloat (const std::string &field) const override |
| | Get float field value.
|
| virtual const std::string & | getString (const std::string &field) const override |
| | Get string field value.
|
| int | getInt (const std::string &field, unsigned int index) const override |
| | Get array int field value.
|
| long | getLong (const std::string &field, unsigned int index) const override |
| | Get array long field value.
|
| double | getDouble (const std::string &field, unsigned int index) const override |
| | Get array double field value.
|
| float | getFloat (const std::string &field, unsigned int index) const override |
| | Get array float field value.
|
| virtual const std::string & | getString (const std::string &field, unsigned int index) const override |
| | Get array string field value.
|
| void | dump () const |
| | Dump to cout.
|
| void | addValue (const std::string &field, SqliteInp value) |
SqliteRecord is one record in the SqliteRecordset object.
Definition at line 48 of file SqliteRecord.h.
◆ FieldCheckResult
◆ Record
◆ RecordCIterator
◆ FieldCheckCode
| Enumerator |
|---|
| FIELD_CHECK_OK | |
| FIELD_CHECK_BAD_NAME | |
| FIELD_CHECK_BAD_TYPE | |
| FIELD_CHECK_NULL_VAL | |
Definition at line 131 of file SqliteRecord.h.
◆ SqliteRecord() [1/3]
◆ SqliteRecord() [2/3]
| SqliteRecord::SqliteRecord |
( |
| ) |
|
|
delete |
◆ SqliteRecord() [3/3]
◆ ~SqliteRecord()
| SqliteRecord::~SqliteRecord |
( |
| ) |
|
|
override |
◆ addValue()
| void SqliteRecord::addValue |
( |
const std::string & | field, |
|
|
SqliteInp | value ) |
Definition at line 103 of file SqliteRecord.cxx.
105{
107 if(!result) throw std::runtime_error("Unexpected error when adding new value for the field " +
108 field + ". Duplicate field name?");
109}
◆ checkField()
Definition at line 149 of file SqliteRecord.h.
151{
154
155 auto defIt =
m_def->find(field);
158
163 }
164 }
165 return std::make_tuple(checkIt,checkCode);
166}
Record::const_iterator RecordCIterator
◆ dump()
| void SqliteRecord::dump |
( |
| ) |
const |
Dump to cout.
Definition at line 111 of file SqliteRecord.cxx.
112{
113 boost::io::ios_all_saver saver (std::cout);
115 for(
const auto& [colName,colType] : *
m_def) {
116 if(first) {
118 }
119 else {
120 std::cout << ", ";
121 }
122 auto recIt =
m_record.find(colName);
123 bool fieldNull = (recIt==
m_record.end());
124 std::cout << "[" << colName << " (";
125 switch(colType) {
127 std::cout << "int) : " << (fieldNull? "NULL" : std::to_string(std::get<int>(recIt->second))) << "]";
128 break;
130 std::cout << "long) : " << (fieldNull? "NULL" : std::to_string(std::get<long>(recIt->second))) << "]";
131 break;
133 std::cout << "float) : ";
134 if (fieldNull) {
135 std::cout << "NULL";
136 }
137 else {
138 std::cout << std::setprecision(10) << std::get<float>(recIt->second) << "]";
139 }
140 break;
142 std::cout << "double) : ";
143 if (fieldNull) {
144 std::cout << "NULL";
145 }
146 else {
147 std::cout << std::setprecision(10) << std::get<double>(recIt->second) << "]";
148 }
149 break;
151 std::cout << "string) : " << (fieldNull? "NULL" : ("\"" + std::get<std::string>(recIt->second)) + "\"") << "]";
152 break;
153 default:
154 std::cout << "ERROR) : ]";
155 }
156 }
157 std::cout << std::endl;
158}
◆ getDouble() [1/2]
| double SqliteRecord::getDouble |
( |
const std::string & | field | ) |
const |
|
overridevirtual |
Get double field value.
- Parameters
-
- Returns
- field value
Implements IRDBRecord.
Definition at line 52 of file SqliteRecord.cxx.
53{
56 return std::get<double>(recIt->second);
57 }
59 return 0.;
60}
FieldCheckResult checkField(const std::string &field, SqliteInpType fieldType) const
void handleError(const std::string &field, FieldCheckCode checkCode) const
◆ getDouble() [2/2]
| double SqliteRecord::getDouble |
( |
const std::string & | field, |
|
|
unsigned int | index ) const |
|
overridevirtual |
Get array double field value.
- Parameters
-
| field | [IN] field name |
| index | [IN] index in the array |
- Returns
- field value
Implements IRDBRecord.
Definition at line 88 of file SqliteRecord.cxx.
89{
90 return getDouble(field +
"_" + std::to_string(index));
91}
double getDouble(const std::string &field) const override
Get double field value.
◆ getFloat() [1/2]
| float SqliteRecord::getFloat |
( |
const std::string & | field | ) |
const |
|
overridevirtual |
◆ getFloat() [2/2]
| float SqliteRecord::getFloat |
( |
const std::string & | field, |
|
|
unsigned int | index ) const |
|
overridevirtual |
Get array float field value.
- Parameters
-
| field | [IN] field name |
| index | [IN] index in the array |
- Returns
- field value
Implements IRDBRecord.
Definition at line 93 of file SqliteRecord.cxx.
94{
95 return getFloat(field +
"_" + std::to_string(index));
96}
float getFloat(const std::string &field) const override
Get float field value.
◆ getInt() [1/2]
| int SqliteRecord::getInt |
( |
const std::string & | field | ) |
const |
|
overridevirtual |
Get int field value.
- Parameters
-
- Returns
- field value
Implements IRDBRecord.
Definition at line 36 of file SqliteRecord.cxx.
37{
40 return std::get<int>(recIt->second);
41 }
43 return 0;
44}
◆ getInt() [2/2]
| int SqliteRecord::getInt |
( |
const std::string & | field, |
|
|
unsigned int | index ) const |
|
overridevirtual |
Get array int field value.
- Parameters
-
| field | [IN] field name |
| index | [IN] index in the array |
- Returns
- field value
Implements IRDBRecord.
Definition at line 78 of file SqliteRecord.cxx.
79{
80 return getInt(field +
"_" + std::to_string(index));
81}
int getInt(const std::string &field) const override
Get int field value.
◆ getLong() [1/2]
| long SqliteRecord::getLong |
( |
const std::string & | field | ) |
const |
|
overridevirtual |
◆ getLong() [2/2]
| long SqliteRecord::getLong |
( |
const std::string & | field, |
|
|
unsigned int | index ) const |
|
overridevirtual |
Get array long field value.
- Parameters
-
| field | [IN] field name |
| index | [IN] index in the array |
- Returns
- field value
Implements IRDBRecord.
Definition at line 83 of file SqliteRecord.cxx.
84{
85 return getLong(field +
"_" + std::to_string(index));
86}
long getLong(const std::string &field) const override
Get long field value.
◆ getString() [1/2]
| const std::string & SqliteRecord::getString |
( |
const std::string & | field | ) |
const |
|
overridevirtual |
Get string field value.
- Parameters
-
- Returns
- field value
Implements IRDBRecord.
Definition at line 68 of file SqliteRecord.cxx.
69{
72 return std::get<std::string>(recIt->second);
73 }
75 throw std::runtime_error("Unexpected error in SqliteRecord::getString()");
76}
◆ getString() [2/2]
| const std::string & SqliteRecord::getString |
( |
const std::string & | field, |
|
|
unsigned int | index ) const |
|
overridevirtual |
Get array string field value.
- Parameters
-
| field | [IN] field name |
| index | [IN] index in the array |
- Returns
- field value
Implements IRDBRecord.
Definition at line 98 of file SqliteRecord.cxx.
99{
100 return getString(field +
"_" + std::to_string(index));
101}
virtual const std::string & getString(const std::string &field) const override
Get string field value.
◆ handleError()
| void SqliteRecord::handleError |
( |
const std::string & | field, |
|
|
FieldCheckCode | checkCode ) const |
|
inlineprivate |
Definition at line 168 of file SqliteRecord.h.
170{
171 switch(checkCode) {
173 throw std::runtime_error( "Wrong name for the field " + field);
175 throw std::runtime_error( "Wrong data type requested for the field " + field);
177 throw std::runtime_error( field + " is NULL");
178 default:
179 break;
180 }
181 return;
182}
◆ isFieldNull()
| bool SqliteRecord::isFieldNull |
( |
const std::string & | field | ) |
const |
|
overridevirtual |
Check if the field value is NULL.
- Parameters
-
| field | [IN] field name @retun TRUE if the field is NULL, FALSE otherwise |
Implements IRDBRecord.
Definition at line 29 of file SqliteRecord.cxx.
30{
32 if(
m_def->find(field)==
m_def->end())
throw std::runtime_error(
"Wrong name for the field "+ field);
33 return true;
34}
◆ operator=()
◆ m_def
◆ m_record
The documentation for this class was generated from the following files: