ATLAS Offline Software
Loading...
Searching...
No Matches
SqliteRecord.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
11
12#ifndef RDBACCESSSVC_SQLITERECORD_H
13#define RDBACCESSSVC_SQLITERECORD_H
14
16#include <map>
17#include <memory>
18#include <variant>
19#include <string>
20#include <string_view>
21#include <tuple>
22
32
33typedef std::variant<int
34 , long
35 , float
36 , double
37 , std::string> SqliteInp;
38
39typedef std::map<std::string,SqliteInpType, std::less<>> SqliteInpDef;
40typedef std::shared_ptr<SqliteInpDef> SqliteInpDef_ptr;
41
47
48class SqliteRecord final : public IRDBRecord
49{
50 public:
52 SqliteRecord() = delete;
53 SqliteRecord (const SqliteRecord&) = delete;
55
57 ~SqliteRecord() override;
58
62 bool isFieldNull(std::string_view field) const override;
63
67 int getInt(std::string_view field) const override;
68
72 long getLong(std::string_view field) const override;
73
77 double getDouble(std::string_view field) const override;
78
82 float getFloat(std::string_view field) const override;
83
87 virtual const std::string& getString(std::string_view field) const override;
88
89 // Access array values by index
90 // arrays are implemented using the field with names like NAME_0, NAME_1 etc.
91
96 int getInt(std::string_view field, unsigned int index) const override;
97
102 long getLong(std::string_view field, unsigned int index) const override;
103
108 double getDouble(std::string_view field, unsigned int index) const override;
109
114 float getFloat(std::string_view field, unsigned int index) const override;
115
120 virtual const std::string& getString(std::string_view field, unsigned int index) const override;
121
123 void dump() const;
124
125 void addValue(std::string_view field, SqliteInp value);
126
127 private:
128 typedef std::map<std::string,SqliteInp, std::less<>> Record;
129 typedef Record::const_iterator RecordCIterator;
137 typedef std::tuple<RecordCIterator,FieldCheckCode> FieldCheckResult;
138
141
142 FieldCheckResult checkField(std::string_view field, SqliteInpType fieldType) const;
143 void handleError(std::string_view field, FieldCheckCode checkCode) const;
144};
145
147 , SqliteInpType fieldType) const
148{
150 RecordCIterator checkIt{m_record.end()};
151
152 auto defIt = m_def->find(field);
153 if(defIt==m_def->end()) checkCode = FIELD_CHECK_BAD_NAME;
154 else if(defIt->second!=fieldType) checkCode = FIELD_CHECK_BAD_TYPE;
155
156 if(checkCode==FIELD_CHECK_OK) {
157 checkIt = m_record.find(field);
158 if(checkIt==m_record.end()) {
159 checkCode = FIELD_CHECK_NULL_VAL;
160 }
161 }
162 return std::make_tuple(checkIt,checkCode);
163}
164
165#endif
166
Definition of the abstract IRDBRecord interface.
std::shared_ptr< SqliteInpDef > SqliteInpDef_ptr
std::map< std::string, SqliteInpType, std::less<> > SqliteInpDef
std::variant< int, long, float, double, std::string > SqliteInp
SqliteInpType
@ SQLITEINP_UNDEF
@ SQLITEINP_FLOAT
@ SQLITEINP_STRING
@ SQLITEINP_DOUBLE
@ SQLITEINP_LONG
@ SQLITEINP_INT
IRDBRecord is one record in the IRDBRecordset object.
Definition IRDBRecord.h:28
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)
std::tuple< RecordCIterator, FieldCheckCode > FieldCheckResult
Record::const_iterator RecordCIterator
void dump() const
Dump to cout.
SqliteRecord(const SqliteRecord &)=delete
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.
std::map< std::string, SqliteInp, std::less<> > Record
double getDouble(std::string_view field) const override
Get double field value.
SqliteRecord & operator=(const SqliteRecord &)=delete
SqliteInpDef_ptr m_def
long getLong(std::string_view field) const override
Get long field value.
SqliteRecord()=delete
SqliteRecord(SqliteInpDef_ptr def)
~SqliteRecord() override
Destructor.
Definition index.py:1