1#ifndef DBA_DB_V7_CURSOR_H
2#define DBA_DB_V7_CURSOR_H
5#include <dballe/db/v7/levtr.h>
7#include <dballe/db/v7/transaction.h>
29 mutable std::unique_ptr<DBValues> values;
33 void dump(FILE* out)
const;
42 std::unique_ptr<wreport::Var> var)
43 : station(station), value(id_data, std::move(var))
46 StationDataRow(
const StationDataRow&) =
delete;
47 StationDataRow(StationDataRow&& o) =
default;
48 StationDataRow& operator=(
const StationDataRow&) =
delete;
49 StationDataRow& operator=(StationDataRow&& o) =
default;
52 void dump(FILE* out)
const;
55struct DataRow :
public StationDataRow
60 using StationDataRow::StationDataRow;
63 const Datetime& datetime,
int id_data,
64 std::unique_ptr<wreport::Var> var)
65 : StationDataRow(station, id_data, std::move(var)), id_levtr(id_levtr),
70 void dump(FILE* out)
const;
77 wreport::Varcode code;
84 : station(station), id_levtr(id_levtr), code(code), dtrange(dtrange),
89 void dump(FILE* out)
const;
128template <
typename Impl>
struct Base :
public ImplTraits<Impl>::Parent
134 std::shared_ptr<v7::Transaction>
tr;
142 Base(std::shared_ptr<v7::Transaction>
tr) :
tr(
tr) {}
146 int remaining()
const override;
147 bool has_value()
const override {
return !
at_start && !
results.empty(); }
157 void discard()
override
173 inline static std::shared_ptr<Impl> downcast(std::shared_ptr<Interface> c)
175 auto res = std::dynamic_pointer_cast<Impl>(c);
177 throw std::runtime_error(
178 "Attempted to downcast the wrong kind of cursor");
182 const Row& row()
const {
return results.front(); }
185 int get_priority()
const
187 return tr->repinfo().get_priority(
results.front().station.report);
191extern template class Base<Stations>;
192extern template class Base<StationData>;
193extern template class Base<Data>;
194extern template class Base<Summary>;
200 DBValues get_values()
const override;
202 void remove()
override;
209 friend std::shared_ptr<dballe::CursorStation>
210 run_station_query(
Tracer<>& trc, std::shared_ptr<v7::Transaction>
tr,
215struct StationData :
public Base<StationData>
217 bool with_attributes;
220 std::shared_ptr<dballe::db::Transaction> get_transaction()
const override
224 wreport::Varcode get_varcode()
const override {
return row().value.code(); }
225 wreport::Var get_var()
const override {
return *row().value; }
226 int attr_reference_id()
const override {
return row().value.data_id; }
227 void query_attrs(std::function<
void(std::unique_ptr<wreport::Var>)> dest,
228 bool force_read)
override;
229 void remove()
override;
235 friend std::shared_ptr<dballe::CursorStationData>
236 run_station_data_query(
Tracer<>& trc, std::shared_ptr<v7::Transaction>
tr,
240template <
typename Impl>
struct LevTrBase :
public Base<Impl>
248 if (levtr ==
nullptr)
252 this->tr->levtr().lookup_cache(this->results.front().id_levtr));
257 using Base<Impl>::Base;
262 return Base<Impl>::next();
265 void discard()
override
268 Base<Impl>::discard();
281 const Datetime& datetime,
int id_data,
282 std::unique_ptr<wreport::Var> var);
286 const Datetime& datetime,
int id_data,
287 std::unique_ptr<wreport::Var> var);
294 bool with_attributes;
298 std::shared_ptr<dballe::db::Transaction> get_transaction()
const override
303 Datetime get_datetime()
const override {
return row().datetime; }
304 wreport::Varcode get_varcode()
const override {
return row().value.code(); }
305 wreport::Var get_var()
const override {
return *row().value; }
306 int attr_reference_id()
const override {
return row().value.data_id; }
307 Level get_level()
const override {
return get_levtr().
level; }
308 Trange get_trange()
const override {
return get_levtr().trange; }
310 void query_attrs(std::function<
void(std::unique_ptr<wreport::Var>)> dest,
311 bool force_read)
override;
312 void remove()
override;
313 void enq(impl::Enq& enq)
const override;
316 friend std::shared_ptr<dballe::CursorData>
317 run_data_query(Tracer<>& trc, std::shared_ptr<v7::Transaction>
tr,
318 const core::Query& query,
bool explain);
326 DatetimeRange get_datetimerange()
const override {
return row().dtrange; }
327 Level get_level()
const override {
return get_levtr().level; }
328 Trange get_trange()
const override {
return get_levtr().trange; }
329 wreport::Varcode get_varcode()
const override {
return row().code; }
330 size_t get_count()
const override {
return row().count; }
331 void remove()
override;
337 friend std::shared_ptr<dballe::CursorSummary>
338 run_summary_query(
Tracer<>& trc, std::shared_ptr<v7::Transaction>
tr,
342std::shared_ptr<dballe::CursorStation>
343run_station_query(
Tracer<>& trc, std::shared_ptr<v7::Transaction> tr,
345std::shared_ptr<dballe::CursorStationData>
346run_station_data_query(
Tracer<>& trc, std::shared_ptr<v7::Transaction> tr,
348std::shared_ptr<dballe::CursorData>
349run_data_query(
Tracer<>& trc, std::shared_ptr<v7::Transaction> tr,
351std::shared_ptr<dballe::CursorSummary>
352run_summary_query(
Tracer<>& trc, std::shared_ptr<v7::Transaction> tr,
354void run_delete_query(
Tracer<>& trc, std::shared_ptr<v7::Transaction> tr,
Cursor iterating over data values.
Definition cursor.h:79
Cursor iterating over station data values.
Definition cursor.h:68
Cursor iterating over stations.
Definition cursor.h:58
Cursor iterating over summary entries.
Definition cursor.h:99
Smart pointer for trace::Step objects, which calls done() when going out of scope.
Definition db/v7/fwd.h:45
Functions used to connect to DB-All.e and insert, query and delete data.
Repinfo table management used by the db module.
Container for a wreport::Var pointer, and its database ID.
Definition value.h:71
Collection of DBValue objects, indexed by wreport::Varcode.
Definition values.h:230
Range of datetimes.
Definition types.h:297
Date and time.
Definition types.h:164
Vertical level or layer.
Definition types.h:625
Information on how a value has been sampled or computed with regards to time.
Definition types.h:689
Standard dballe::Query implementation.
Definition core/query.h:36
Level level
Vertical level or layer.
Definition cache.h:20
Definition qbuilder.h:135
Structure used to build and execute a query, and to iterate through the results.
Definition db/v7/cursor.h:129
std::deque< Row > results
Storage for the raw database results.
Definition db/v7/cursor.h:137
unsigned test_iterate(FILE *dump=0) override
Iterate the cursor until the end, returning the number of items.
std::shared_ptr< v7::Transaction > tr
Database to operate on.
Definition db/v7/cursor.h:134
bool at_start
True if we are at the start of the iteration.
Definition db/v7/cursor.h:140
Definition db/v7/cursor.h:56
CursorData implementation.
Definition db/v7/cursor.h:274
bool add_to_last_results(const dballe::DBStation &station, int id_levtr, const Datetime &datetime, int id_data, std::unique_ptr< wreport::Var > var)
Append or replace the last result according to datetime.
bool add_to_best_results(const dballe::DBStation &station, int id_levtr, const Datetime &datetime, int id_data, std::unique_ptr< wreport::Var > var)
Append or replace the last result according to priority.
Definition db/v7/cursor.h:93
Definition db/v7/cursor.h:241
Definition db/v7/cursor.h:37
CursorStationData implementation.
Definition db/v7/cursor.h:216
Row resulting from a station query.
Definition db/v7/cursor.h:27
CursorStation implementation.
Definition db/v7/cursor.h:198
Definition db/v7/cursor.h:74
CursorSummary implementation.
Definition db/v7/cursor.h:323
Class passed to key-value accessors to set values in an invoker-defined way.
Definition core/enq.h:18
Common base types used by most of DB-All.e code.
Structures used as input to database insert functions.