1 #ifndef DBA_DB_V7_CURSOR_H
2 #define DBA_DB_V7_CURSOR_H
6 #include <dballe/db/v7/transaction.h>
8 #include <dballe/db/v7/levtr.h>
28 mutable std::unique_ptr<DBValues> values;
32 void dump(FILE* out)
const;
47 void dump(FILE* out)
const;
55 using StationDataRow::StationDataRow;
58 :
StationDataRow(station, id_data, std::move(var)), id_levtr(id_levtr), datetime(datetime) {}
60 void dump(FILE* out)
const;
72 : station(station), id_levtr(id_levtr), code(code), dtrange(dtrange), count(count) {}
74 void dump(FILE* out)
const;
78 template<
typename Row>
82 std::shared_ptr<v7::Transaction>
tr;
88 typename std::vector<Row>::const_iterator
cur;
93 Rows(std::shared_ptr<v7::Transaction>
tr) :
tr(
tr) {}
95 const Row* operator->()
const {
return &*
cur; }
97 int get_priority()
const {
return tr->repinfo().get_priority(
cur->station.report); }
130 template<
typename Row>
152 if (levtr ==
nullptr)
154 levtr = &(this->tr->levtr().lookup_cache(this->cur->id_levtr));
161 using LevTrRows::LevTrRows;
167 using BaseDataRows::BaseDataRows;
180 using LevTrRows::LevTrRows;
186 template<
typename Cursor>
232 template<
typename Impl>
241 Base(std::shared_ptr<v7::Transaction> tr)
248 int remaining()
const override;
249 bool has_value()
const {
return !rows.at_start && rows.cur != rows.results.end(); }
250 bool next()
override {
return rows.next(); }
251 void discard()
override;
255 void enq(
impl::Enq& enq)
const override {
return rows.enq(enq); }
265 inline static std::unique_ptr<Impl>
downcast(std::unique_ptr<Interface> c)
267 Impl* res = dynamic_cast<Impl*>(c.get());
268 if (!res)
throw std::runtime_error(
"Attempted to downcast the wrong kind of cursor");
270 return std::unique_ptr<Impl>(res);
274 extern template class Base<Stations>;
275 extern template class Base<StationData>;
276 extern template class Base<Data>;
277 extern template class Base<Summary>;
284 DBValues get_values()
const override;
286 void remove()
override;
292 bool with_attributes;
295 std::shared_ptr<dballe::db::Transaction> get_transaction()
const override {
return rows.tr; }
296 wreport::Varcode get_varcode()
const override {
return rows->value.code(); }
297 wreport::Var get_var()
const override {
return *rows->value; }
298 int attr_reference_id()
const override {
return rows->value.data_id; }
299 void query_attrs(std::function<
void(std::unique_ptr<wreport::Var>)> dest,
bool force_read)
override;
300 void remove()
override;
306 bool with_attributes;
310 std::shared_ptr<dballe::db::Transaction> get_transaction()
const override {
return rows.tr; }
312 Datetime get_datetime()
const override {
return rows->datetime; }
313 wreport::Varcode get_varcode()
const override {
return rows->value.code(); }
314 wreport::Var get_var()
const override {
return *rows->value; }
315 int attr_reference_id()
const override {
return rows->value.data_id; }
316 Level get_level()
const override {
return rows.get_levtr().level; }
317 Trange get_trange()
const override {
return rows.get_levtr().trange; }
319 void query_attrs(std::function<
void(std::unique_ptr<wreport::Var>)> dest,
bool force_read)
override;
320 void remove()
override;
330 return this->rows->dtrange;
332 Level get_level()
const override {
return rows.get_levtr().level; }
333 Trange get_trange()
const override {
return rows.get_levtr().trange; }
335 size_t get_count()
const override {
return rows->count; }
336 void remove()
override;
340 std::unique_ptr<dballe::CursorStation> run_station_query(
Tracer<>& trc, std::shared_ptr<v7::Transaction> tr,
const core::Query& query,
bool explain);
341 std::unique_ptr<dballe::CursorStationData> run_station_data_query(
Tracer<>& trc, std::shared_ptr<v7::Transaction> tr,
const core::Query& query,
bool explain);
342 std::unique_ptr<dballe::CursorData> run_data_query(
Tracer<>& trc, std::shared_ptr<v7::Transaction> tr,
const core::Query& query,
bool explain);
343 std::unique_ptr<dballe::CursorSummary> run_summary_query(
Tracer<>& trc, std::shared_ptr<v7::Transaction> tr,
const core::Query& query,
bool explain);
344 void run_delete_query(
Tracer<>& trc, std::shared_ptr<v7::Transaction> tr,
const core::Query& query,
bool station_vars,
bool explain);
Cursor iterating over stations.
Definition: cursor.h:56
Definition: qbuilder.h:124
Container for a wreport::Var pointer, and its database ID.
Definition: value.h:71
unsigned test_iterate(FILE *dump=0) override
Iterate the cursor until the end, returning the number of items.
Class passed to key-value accessors to set values in an invoker-defined way.
Definition: core/enq.h:17
Cursor iterating over summary entries.
Definition: cursor.h:97
Definition: db/v7/cursor.h:115
CursorSummary implementation.
Definition: db/v7/cursor.h:324
std::shared_ptr< v7::Transaction > tr
Database to operate on.
Definition: db/v7/cursor.h:82
Smart pointer for trace::Step objects, which calls done() when going out of scope.
Definition: db/v7/fwd.h:45
CursorData implementation.
Definition: db/v7/cursor.h:304
Definition: db/v7/cursor.h:159
Structure used to build and execute a query, and to iterate through the results.
Definition: db/v7/cursor.h:233
std::vector< Row > results
Storage for the raw database results.
Definition: db/v7/cursor.h:85
static std::unique_ptr< Impl > downcast(std::unique_ptr< Interface > c)
Downcast a unique_ptr pointer.
Definition: db/v7/cursor.h:265
Collection of DBValue objects, indexed by wreport::Varcode.
Definition: values.h:191
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. Returns false if the value has been ignored.
Definition: qbuilder.h:81
Definition: db/v7/cursor.h:63
Range of datetimes.
Definition: types.h:294
std::vector< Row >::const_iterator cur
Iterator to the current position in results.
Definition: db/v7/cursor.h:88
Row resulting from a station query.
Definition: db/v7/cursor.h:25
Information on how a value has been sampled or computed with regards to time.
Definition: types.h:686
Vertical level or layer.
Definition: types.h:624
Definition: db/v7/cursor.h:123
Cursor iterating over station data values.
Definition: cursor.h:66
Definition: db/v7/cursor.h:50
Definition: db/v7/cursor.h:35
Definition: db/v7/cursor.h:178
bool at_start
True if we are at the start of the iteration.
Definition: db/v7/cursor.h:91
Cursor iterating over data values.
Definition: cursor.h:77
Definition: db/v7/cursor.h:79
Date and time.
Definition: types.h:164
Definition: db/v7/cursor.h:187
CursorStationData implementation.
Definition: db/v7/cursor.h:290
Definition: db/v7/cursor.h:165
Standard dballe::Query implementation.
Definition: core/query.h:31
CursorStation implementation.
Definition: db/v7/cursor.h:281
Definition: db/v7/cursor.h:131
Definition: qbuilder.h:91