TkN 2.4
Toolkit for Nuclei
Loading...
Searching...
No Matches
tkdb_table.h
1/********************************************************************************
2 * Copyright (c) : Université de Lyon 1, CNRS/IN2P3, UMR5822, *
3 * IP2I, F-69622 Villeurbanne Cedex, France *
4 * Normandie Université, ENSICAEN, UNICAEN, CNRS/IN2P3, *
5 * LPC Caen, F-14000 Caen, France *
6 * Contibutor(s) : *
7 * Jérémie Dudouet jeremie.dudouet@cnrs.fr [2020] *
8 * Diego Gruyer diego.gruyer@cnrs.fr [2020] *
9 * *
10 * Licensed under the MIT License <http://opensource.org/licenses/MIT>. *
11 * SPDX-License-Identifier: MIT *
12 ********************************************************************************/
13
14#ifndef tkdb_table_H
15#define tkdb_table_H
16
17#include <map>
18#include <iostream>
19
20#include "sqlite3.h"
21#include "tkstring.h"
22#include "tkdb_column.h"
23
24namespace tkn {
25
26typedef std::map<tkstring,tkdb_column> row;
27
29{
30
31 /* data types in sqlite3
32#define SQLITE_INTEGER 1
33#define SQLITE_FLOAT 2
34#define SQLITE_BLOB 4
35#define SQLITE_NULL 5
36#ifdef SQLITE_TEXT
37# undef SQLITE_TEXT
38#else
39# define SQLITE_TEXT 3
40#endif
41#define SQLITE3_TEXT 3
42 */
43
44public:
45
50 // never ever ever change the order of the fields
51 double value = 0.;
52 double err = 0.;
53 double err_low = 0.;
54 double err_high = 0.;
57 bool filled = false;
58
59 void clear() {
60 value = 0.;
61 err = 0.;
62 err_low = 0.;
63 err_high = 0.;
64 unit = "";
65 info = "";
66 filled = false;
67 }
68
69 void print() {
70 std::cout<<"value : "<<value<<std::endl;
71 std::cout<<"unit : "<<unit<<std::endl;
72 std::cout<<"err : "<<err<<std::endl;
73 std::cout<<"err_low : "<<err_low<<std::endl;
74 std::cout<<"err_high: "<<err_high<<std::endl;
75 std::cout<<"info : "<<info<<std::endl;
76 }
77 };
78
79protected:
80 tkstring fName;
81 sqlite3* fDataBase{}; // pointer to the sql database owning the table
82 row fColumns; // map of db_columns ('name', column)
83 std::vector<tkstring> fOrderedColumnNames; // column name in insertion order
84 sqlite3_stmt* fSQL_stmt{}; // sql statement to select rows and loop over them (begin() next() end())
85 bool fReading = false;
86 tkstring fConstraint;
87
88 public:
89 tkdb_table(const char* _name, sqlite3 *_db);
91 virtual ~tkdb_table();
92
93 tkstring get_name(){return fName;}
94
95 tkdb_column &operator[](const char* _column) {
96 return fColumns[_column];
97 }
98
99 void print(const tkstring &_opt="");
100 void print_columns(const tkstring &_opt="");
101 void print_rows(const char* _selection, const char *_properties="*");
102
103 void begin(tkstring _condition, tkstring _selection="*");
104 bool next();
105 void end();
106
107 void load();
108 void add_column(const char *_colname, const char *_coltype);
109 void add_constraint(const char *_constraint);
110 bool has_column(const tkstring &_col_name);
111 void reset_column_values();
112 void push_row();
113 void update_row(const tkstring &_where);
114 void write_to_database();
115 void push_dummy_row();
116 row & get_columns(){return fColumns;}
117
118 void read_measure(measure_data_struct &_struct, const tkstring &_col_base_name);
119
120private:
121 int exec_sql(const char *_cmd);
122
123#ifdef HAS_ROOT
125 ClassDef(tkdb_table,0);
126#endif
127
128};
129}
130#endif
Simple structure to store a table column.
Definition tkdb_column.h:26
Representaiton of a sqlite data table.
Definition tkdb_table.h:29
void read_measure(measure_data_struct &_struct, const tkstring &_col_base_name)
tkdb_column & operator[](const char *_column)
Definition tkdb_table.h:95
void begin(tkstring _condition, tkstring _selection="*")
bool has_column(const tkstring &_col_name)
row & get_columns()
Definition tkdb_table.h:116
void update_row(const tkstring &_where)
void load()
resets column values and ends the select statement
bool next()
executes the select statement
void print_columns(const tkstring &_opt="")
tkstring get_name()
Definition tkdb_table.h:93
void add_constraint(const char *_constraint)
void write_to_database()
void print_rows(const char *_selection, const char *_properties="*")
void end()
reads the next entry coresponding to the select statement and fills columns
void print(const tkstring &_opt="")
void add_column(const char *_colname, const char *_coltype)
void reset_column_values()
virtual ~tkdb_table()
tkdb_table(const char *_name, sqlite3 *_db)
std::string with usefull tricks from TString (ROOT) and KVString (KaliVeda) and more....
Definition tkstring.h:31
Definition tklog.cpp:16
std::map< tkstring, tkdb_column > row
Definition tkdb_table.h:26
data structure used to fill a tkmeasure object from the sqlite database
Definition tkdb_table.h:49