libdballe  6.8
qbuilder.h
Go to the documentation of this file.
1 /*
2  * db/v6/qbuilder - build SQL queries for V6 databases
3  *
4  * Copyright (C) 2005--2013 ARPA-SIM <urpsim@smr.arpa.emr.it>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * Author: Enrico Zini <enrico@enricozini.com>
20  */
21 
28 #ifndef DBA_DB_V6_QBUILDER_H
29 #define DBA_DB_V6_QBUILDER_H
30 
31 #include "dballe/db/querybuf.h"
32 #include "dballe/db/internals.h"
33 #include "dballe/db/db.h"
34 #include "dballe/core/record.h"
35 #include "db.h"
36 #include "cursor.h"
37 #include <regex.h>
38 
39 #if 0
40 
44 #define DBA_DB_FROM_PA (1 << 0)
45 
46 #define DBA_DB_FROM_LTR (1 << 1)
47 
48 #define DBA_DB_FROM_D (1 << 2)
49 
50 #define DBA_DB_FROM_RI (1 << 3)
51 
52 #define DBA_DB_FROM_DBLO (1 << 5)
53 
54 #define DBA_DB_FROM_DSTA (1 << 6)
55 
56 #define DBA_DB_FROM_DANA (1 << 7)
57 
59 #define DBA_DB_FROM_DDF (1 << 8)
60 
62 #define DBA_DB_FROM_ADF (1 << 9)
63 #endif
64 
65 namespace dballe {
66 namespace db {
67 namespace v6 {
68 
74 {
76  SQL_TIMESTAMP_STRUCT sel_dtmin;
78  SQL_TIMESTAMP_STRUCT sel_dtmax;
80  unsigned int input_seq;
81 
82  ExtraQueryArgs() : input_seq(1) {};
83 };
84 
86 {
88  DB& db;
89 
92 
95 
97  const Record& rec;
98 
101 
104 
107 
109  const unsigned int modifiers;
110 
111  ExtraQueryArgs qargs;
112 
114  unsigned int output_seq;
115 
118 
119 #if 0
120 
121  unsigned int wanted;
122 
124  unsigned int select_wanted;
125 
127  unsigned int from_wanted;
128 
130  bool has_orderby;
131 #endif
132 
133  QueryBuilder(DB& db, Statement& stm, Cursor& cur, const Record& rec, unsigned int modifiers);
134  virtual ~QueryBuilder() {}
135 
136  void build();
137 
138 protected:
139  // Add WHERE conditions
140  bool add_pa_where(const char* tbl);
141  bool add_dt_where(const char* tbl);
142  bool add_ltr_where(const char* tbl);
143  bool add_varcode_where(const char* tbl);
144  bool add_repinfo_where(const char* tbl);
145  bool add_datafilter_where(const char* tbl);
146  bool add_attrfilter_where(const char* tbl);
147 
148  virtual void build_select() = 0;
149  virtual bool build_where() = 0;
150  virtual void build_order_by() = 0;
151 
152 #if 0
153 
156  void add_to_orderby(const char* fields);
157 
165  void add_other_froms(unsigned int base, const Record& rec);
166 
168  void resolve_dependencies();
169 
171  void make_select();
172 
177  void make_extra_select();
178 
180  void make_from(const Record& rec);
181 
183  void add_int(const Record& rec, dba_keyword key, const char* sql, int needed_from);
184 
186  void make_where(const Record& rec);
187 
189  void add_repinfo_where(Querybuf& buf, const Record& query, const char* colname);
190 
192  void build_query(const Record& rec);
193 
195  void build_count_query(const Record& rec);
196 
198  void build_date_extremes_query(const Record& rec);
199 #endif
200 };
201 
203 {
204  StationQueryBuilder(DB& db, Statement& stm, Cursor& cur, const Record& rec, unsigned int modifiers)
205  : QueryBuilder(db, stm, cur, rec, modifiers) {}
206 
207  virtual void build_select();
208  virtual bool build_where();
209  virtual void build_order_by();
210 };
211 
213 {
214  int query_data_id;
215 
216  DataQueryBuilder(DB& db, Statement& stm, Cursor& cur, const Record& rec, unsigned int modifiers);
217 
218  virtual void build_select();
219  virtual bool build_where();
220  virtual void build_order_by();
221 };
222 
224 {
225  IdQueryBuilder(DB& db, Statement& stm, Cursor& cur, const Record& rec, unsigned int modifiers)
226  : DataQueryBuilder(db, stm, cur, rec, modifiers) {}
227 
228  virtual void build_select();
229  virtual void build_order_by();
230 };
231 
233 {
234  CursorSummary& cur_s;
235 
237  : DataQueryBuilder(db, stm, cur, rec, modifiers), cur_s(cur) {}
238 
239  virtual void build_select();
240  virtual void build_order_by();
241 };
242 
243 }
244 }
245 }
246 
247 #endif
Definition: qbuilder.h:232
Cursor & cur
Cursor with the output variables.
Definition: qbuilder.h:94
Structure used to build and execute a query, and to iterate through the results.
Definition: v6/cursor.h:58
unsigned int input_seq
Positional sequence number to use to bind ODBC input parameters.
Definition: qbuilder.h:80
DB-All.E record.
Definition: record.h:102
Definition: cmdline.h:34
String buffer for composing database queries.
Definition: querybuf.h:35
SQL_TIMESTAMP_STRUCT sel_dtmin
Minimum datetime.
Definition: qbuilder.h:76
Functions used to connect to DB-All.e and insert, query and delete data.
Definition: qbuilder.h:202
Implementation of an efficient string buffer for composing database queries.
Querybuf sql_where
WHERE part of the SQL query.
Definition: qbuilder.h:106
bool query_station_vars
True if we are querying station information, rather than measured data.
Definition: qbuilder.h:117
DB & db
Database to operate on.
Definition: qbuilder.h:88
const Record & rec
Record with the query.
Definition: qbuilder.h:97
unsigned int output_seq
Sequence number to use to bind ODBC output parameters.
Definition: qbuilder.h:114
Querybuf sql_from
FROM part of the SQL query.
Definition: qbuilder.h:103
Querybuf sql_query
Dynamically generated SQL query.
Definition: qbuilder.h:100
ODBC statement.
Definition: internals.h:220
Implement a storage object for a group of related observation data.
Database functions and data structures used by the db module, but not exported as official API...
Copies of bind values that cannot be bound to data inside the query Record.
Definition: qbuilder.h:73
Functions used to manage a general DB-ALLe query.
SQL_TIMESTAMP_STRUCT sel_dtmax
Maximum datetime.
Definition: qbuilder.h:78
Definition: qbuilder.h:85
DB-ALLe database connection.
Definition: v6/db.h:87
Definition: qbuilder.h:223
Definition: v6/cursor.h:244
Statement & stm
Statement to build variables to.
Definition: qbuilder.h:91
const unsigned int modifiers
Modifier flags to enable special query behaviours.
Definition: qbuilder.h:109
Definition: qbuilder.h:212