libdballe  9.14
qbuilder.h
1 #ifndef DBA_DB_V7_QBUILDER_H
2 #define DBA_DB_V7_QBUILDER_H
3 
4 #include <dballe/core/query.h>
5 #include <dballe/db/v7/db.h>
6 #include <dballe/sql/querybuf.h>
7 #include <regex.h>
8 
9 namespace dballe {
10 struct Varmatch;
11 
12 namespace db {
13 namespace v7 {
14 
17 {
19 
21  std::shared_ptr<v7::Transaction> tr;
22 
29  const char* bind_in_ident = nullptr;
30 
31  bool select_station = false; // ana_id, lat, lon, ident
32 
33  bool select_varinfo = false; // rep_cod, id_ltr, varcode
34 
35  // IdQuery
36  bool select_data_id = false; // id_data
37 
38  // DataQuery
39  bool select_data = false; // datetime, value
40 
41  // SummaryQuery
42  bool select_summary_details = false; // id_data, datetime, datetimemax
43 
46 
49 
52 
55 
57  const unsigned int modifiers;
58 
61 
62  QueryBuilder(std::shared_ptr<v7::Transaction> tr, const core::Query& query,
63  unsigned int modifiers, bool query_station_vars);
64  virtual ~QueryBuilder() {}
65 
66  void build();
67 
68 protected:
69  // Add WHERE conditions
70  bool add_pa_where(const char* tbl);
71  bool add_dt_where(const char* tbl);
72  bool add_ltr_where(const char* tbl);
73  bool add_varcode_where(const char* tbl);
74  bool add_repinfo_where(const char* tbl);
75  bool add_datafilter_where(const char* tbl);
76 
77  virtual void build_select() = 0;
78  virtual bool build_where() = 0;
79  virtual void build_order_by() = 0;
80 };
81 
83 {
84  StationQueryBuilder(std::shared_ptr<v7::Transaction> tr,
85  const core::Query& query, unsigned int modifiers)
86  : QueryBuilder(tr, query, modifiers, false)
87  {
88  }
89 
90  void build_select() override;
91  bool build_where() override;
92  void build_order_by() override;
93 };
94 
96 {
98  Varmatch* attr_filter = nullptr;
99 
102 
104  bool select_attrs = false;
105 
106  DataQueryBuilder(std::shared_ptr<v7::Transaction> tr,
107  const core::Query& query, unsigned int modifiers,
108  bool query_station_vars);
109  ~DataQueryBuilder();
110 
111  // bool add_attrfilter_where(const char* tbl);
112 
114  bool match_attrs(const wreport::Var& var) const;
115 
116  void build_select() override;
117  bool build_where() override;
118  void build_order_by() override;
119 };
120 
122 {
123  IdQueryBuilder(std::shared_ptr<v7::Transaction> tr,
124  const core::Query& query, unsigned int modifiers,
125  bool query_station_vars)
127  {
128  }
129 
130  void build_select() override;
131  void build_order_by() override;
132 };
133 
135 {
136  SummaryQueryBuilder(std::shared_ptr<v7::Transaction> tr,
137  const core::Query& query, unsigned int modifiers,
138  bool query_station_vars)
140  {
141  }
142 
143  void build_select() override;
144  void build_order_by() override;
145 };
146 
147 } // namespace v7
148 } // namespace db
149 } // namespace dballe
150 
151 #endif
Definition: qbuilder.h:82
const core::Query & query
Query object.
Definition: qbuilder.h:45
Definition: qbuilder.h:134
Definition: qbuilder.h:121
bool match_attrs(const wreport::Var &var) const
Match the attributes of var against attr_filter.
std::shared_ptr< v7::Transaction > tr
Database to operate on.
Definition: qbuilder.h:21
const unsigned int modifiers
Modifier flags to enable special query behaviours.
Definition: qbuilder.h:57
Standard dballe::Query implementation.
Definition: core/query.h:35
Match a variable code and value.
Definition: varmatch.h:12
Definition: cmdline.h:18
Build SQL queries for V7 databases.
Definition: qbuilder.h:16
dballe::sql::Querybuf sql_from
FROM part of the SQL query.
Definition: qbuilder.h:51
Definition: sql.h:53
Buffer used to build SQL queries.
bool query_attrs
True if we also query attributes of data.
Definition: qbuilder.h:101
const char * bind_in_ident
If defined, it need to point to the identifier to be used as the only bound input parameter...
Definition: qbuilder.h:29
dballe::sql::Querybuf sql_query
Dynamically generated SQL query.
Definition: qbuilder.h:48
bool select_attrs
True if the select includes the attrs field.
Definition: qbuilder.h:104
Varmatch * attr_filter
Attribute filter, if requested.
Definition: qbuilder.h:98
bool query_station_vars
True if we are querying station information, rather than measured data.
Definition: qbuilder.h:60
String buffer for composing database queries.
Definition: querybuf.h:15
Definition: qbuilder.h:95
dballe::sql::Querybuf sql_where
WHERE part of the SQL query.
Definition: qbuilder.h:54