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); }
103 else if (cur != results.end())
105 return cur != results.end();
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;
172 bool add_to_best_results(
const dballe::DBStation& station,
int id_levtr,
const Datetime& datetime,
int id_data, std::unique_ptr<wreport::Var> var);
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 next()
override {
return rows.next(); }
250 void discard()
override;
254 void enq(
impl::Enq& enq)
const override {
return rows.enq(enq); }
261 unsigned test_iterate(FILE* dump=0)
override;
264 inline static std::unique_ptr<Impl>
downcast(std::unique_ptr<Interface> c)
266 Impl* res =
dynamic_cast<Impl*
>(c.get());
267 if (!res)
throw std::runtime_error(
"Attempted to downcast the wrong kind of cursor");
269 return std::unique_ptr<Impl>(res);
283 DBValues get_values()
const override;
285 void remove()
override;
291 bool with_attributes;
294 std::shared_ptr<dballe::db::Transaction> get_transaction()
const override {
return rows.tr; }
295 wreport::Varcode get_varcode()
const override {
return rows->value.code(); }
296 wreport::Var get_var()
const override {
return *rows->value; }
297 int attr_reference_id()
const override {
return rows->value.data_id; }
298 void query_attrs(std::function<
void(std::unique_ptr<wreport::Var>)> dest,
bool force_read)
override;
299 void remove()
override;
305 bool with_attributes;
309 std::shared_ptr<dballe::db::Transaction> get_transaction()
const override {
return rows.tr; }
311 Datetime get_datetime()
const override {
return rows->datetime; }
312 wreport::Varcode get_varcode()
const override {
return rows->value.code(); }
313 wreport::Var get_var()
const override {
return *rows->value; }
314 int attr_reference_id()
const override {
return rows->value.data_id; }
315 Level get_level()
const override {
return rows.get_levtr().level; }
316 Trange get_trange()
const override {
return rows.get_levtr().trange; }
318 void query_attrs(std::function<
void(std::unique_ptr<wreport::Var>)> dest,
bool force_read)
override;
319 void remove()
override;
329 return this->rows->dtrange;
331 Level get_level()
const override {
return rows.get_levtr().level; }
332 Trange get_trange()
const override {
return rows.get_levtr().trange; }
334 size_t get_count()
const override {
return rows->count; }
335 void remove()
override;
339 std::unique_ptr<dballe::CursorStation> run_station_query(
Tracer<>& trc, std::shared_ptr<v7::Transaction> tr,
const core::Query& query,
bool explain);
340 std::unique_ptr<dballe::CursorStationData> run_station_data_query(
Tracer<>& trc, std::shared_ptr<v7::Transaction> tr,
const core::Query& query,
bool explain);
341 std::unique_ptr<dballe::CursorData> run_data_query(
Tracer<>& trc, std::shared_ptr<v7::Transaction> tr,
const core::Query& query,
bool explain);
342 std::unique_ptr<dballe::CursorSummary> run_summary_query(
Tracer<>& trc, std::shared_ptr<v7::Transaction> tr,
const core::Query& query,
bool explain);
343 void run_delete_query(
Tracer<>& trc, std::shared_ptr<v7::Transaction> tr,
const core::Query& query,
bool station_vars,
bool explain);
Row resulting from a station query.
Definition: db/v7/cursor.h:25
Definition: qbuilder.h:81
Cursor iterating over data values.
Definition: cursor.h:65
CursorStation implementation.
Definition: db/v7/cursor.h:280
CursorStationData implementation.
Definition: db/v7/cursor.h:289
Definition: qbuilder.h:124
Common base types used by most of DB-All.e code.
Class passed to key-value accessors to set values in an invoker-defined way.
Definition: core/enq.h:17
CursorSummary implementation.
Definition: db/v7/cursor.h:323
static std::unique_ptr< Impl > downcast(std::unique_ptr< Interface > c)
Downcast a unique_ptr pointer.
Definition: db/v7/cursor.h:264
Definition: db/v7/cursor.h:159
Information on how a value has been sampled or computed with regards to time.
Definition: types.h:683
Functions used to connect to DB-All.e and insert, query and delete data.
Standard dballe::Query implementation.
Definition: core/query.h:31
std::vector< Row >::const_iterator cur
Iterator to the current position in results.
Definition: db/v7/cursor.h:88
CursorData implementation.
Definition: db/v7/cursor.h:303
Definition: db/v7/cursor.h:187
Definition: db/v7/cursor.h:178
Collection of DBValue objects, indexed by wreport::Varcode.
Definition: values.h:191
Definition: db/v7/cursor.h:35
Cursor iterating over summary entries.
Definition: cursor.h:84
Vertical level or layer.
Definition: types.h:621
Definition: db/v7/cursor.h:165
Range of datetimes.
Definition: types.h:291
std::shared_ptr< v7::Transaction > tr
Database to operate on.
Definition: db/v7/cursor.h:82
Structure used to build and execute a query, and to iterate through the results.
Definition: db/v7/cursor.h:233
Definition: db/v7/cursor.h:50
Cursor iterating over station data values.
Definition: cursor.h:55
Definition: db/v7/cursor.h:63
Cursor iterating over stations.
Definition: cursor.h:46
Smart pointer for trace::Step objects, which calls done() when going out of scope.
Definition: db/v7/fwd.h:45
Date and time.
Definition: types.h:164
Definition: db/v7/cursor.h:115
Definition: db/v7/cursor.h:131
Definition: db/v7/cursor.h:79
Structures used as input to database insert functions.
Repinfo table management used by the db module.
std::vector< Row > results
Storage for the raw database results.
Definition: db/v7/cursor.h:85
Definition: db/v7/cursor.h:123
Container for a wreport::Var pointer, and its database ID.
Definition: value.h:71
Definition: qbuilder.h:91