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> 29 mutable std::unique_ptr<DBValues> values;
33 void dump(FILE* out)
const;
48 void dump(FILE* out)
const;
56 using StationDataRow::StationDataRow;
59 :
StationDataRow(station, id_data, std::move(var)), id_levtr(id_levtr), datetime(datetime) {}
61 void dump(FILE* out)
const;
73 : station(station), id_levtr(id_levtr), code(code), dtrange(dtrange), count(count) {}
75 void dump(FILE* out)
const;
79 template<
typename Cursor>
121 template<
typename Impl>
128 std::shared_ptr<v7::Transaction>
tr;
136 Base(std::shared_ptr<v7::Transaction>
tr)
143 int remaining()
const override;
144 bool has_value()
const override {
return !
at_start && !
results.empty(); }
154 void discard()
override 170 inline static std::shared_ptr<Impl> downcast(std::shared_ptr<Interface> c)
172 auto res = std::dynamic_pointer_cast<Impl>(c);
174 throw std::runtime_error(
"Attempted to downcast the wrong kind of cursor");
178 const Row& row()
const {
return results.front(); }
181 int get_priority()
const {
return tr->repinfo().get_priority(
results.front().station.report); }
184 extern template class Base<Stations>;
185 extern template class Base<StationData>;
186 extern template class Base<Data>;
187 extern template class Base<Summary>;
194 DBValues get_values()
const override;
196 void remove()
override;
203 friend std::shared_ptr<dballe::CursorStation> run_station_query(
Tracer<>& trc, std::shared_ptr<v7::Transaction> tr,
const core::Query& query,
bool explain);
209 bool with_attributes;
212 std::shared_ptr<dballe::db::Transaction> get_transaction()
const override {
return tr; }
213 wreport::Varcode get_varcode()
const override {
return row().value.code(); }
214 wreport::Var get_var()
const override {
return *row().value; }
215 int attr_reference_id()
const override {
return row().value.data_id; }
216 void query_attrs(std::function<
void(std::unique_ptr<wreport::Var>)> dest,
bool force_read)
override;
217 void remove()
override;
223 friend std::shared_ptr<dballe::CursorStationData> run_station_data_query(
Tracer<>& trc, std::shared_ptr<v7::Transaction> tr,
const core::Query& query,
bool explain);
226 template<
typename Impl>
235 if (levtr ==
nullptr)
237 levtr = &(this->tr->levtr().lookup_cache(this->results.front().id_levtr));
250 void discard()
override 264 bool add_to_best_results(
const dballe::DBStation& station,
int id_levtr,
const Datetime& datetime,
int id_data, std::unique_ptr<wreport::Var> var);
266 bool add_to_last_results(
const dballe::DBStation& station,
int id_levtr,
const Datetime& datetime,
int id_data, std::unique_ptr<wreport::Var> var);
273 bool with_attributes;
277 std::shared_ptr<dballe::db::Transaction> get_transaction()
const override {
return tr; }
279 Datetime get_datetime()
const override {
return row().datetime; }
280 wreport::Varcode get_varcode()
const override {
return row().value.code(); }
281 wreport::Var get_var()
const override {
return *row().value; }
282 int attr_reference_id()
const override {
return row().value.data_id; }
283 Level get_level()
const override {
return get_levtr().level; }
284 Trange get_trange()
const override {
return get_levtr().trange; }
286 void query_attrs(std::function<
void(std::unique_ptr<wreport::Var>)> dest,
bool force_read)
override;
287 void remove()
override;
291 friend std::shared_ptr<dballe::CursorData> run_data_query(
Tracer<>& trc, std::shared_ptr<v7::Transaction> tr,
const core::Query& query,
bool explain);
299 DatetimeRange get_datetimerange()
const override {
return row().dtrange; }
300 Level get_level()
const override {
return get_levtr().level; }
301 Trange get_trange()
const override {
return get_levtr().trange; }
303 size_t get_count()
const override {
return row().count; }
304 void remove()
override;
310 friend std::shared_ptr<dballe::CursorSummary> run_summary_query(
Tracer<>& trc, std::shared_ptr<v7::Transaction> tr,
const core::Query& query,
bool explain);
314 std::shared_ptr<dballe::CursorStation> run_station_query(
Tracer<>& trc, std::shared_ptr<v7::Transaction> tr,
const core::Query& query,
bool explain);
315 std::shared_ptr<dballe::CursorStationData> run_station_data_query(
Tracer<>& trc, std::shared_ptr<v7::Transaction> tr,
const core::Query& query,
bool explain);
316 std::shared_ptr<dballe::CursorData> run_data_query(
Tracer<>& trc, std::shared_ptr<v7::Transaction> tr,
const core::Query& query,
bool explain);
317 std::shared_ptr<dballe::CursorSummary> run_summary_query(
Tracer<>& trc, std::shared_ptr<v7::Transaction> tr,
const core::Query& query,
bool explain);
318 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:26
Definition: qbuilder.h:81
CursorStation implementation.
Definition: db/v7/cursor.h:191
CursorStationData implementation.
Definition: db/v7/cursor.h:207
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:295
unsigned test_iterate(FILE *dump=0) override
Iterate the cursor until the end, returning the number of items.
bool at_start
True if we are at the start of the iteration.
Definition: db/v7/cursor.h:134
Information on how a value has been sampled or computed with regards to time.
Definition: types.h:686
Functions used to connect to DB-All.e and insert, query and delete data.
Cursor iterating over summary entries.
Definition: cursor.h:97
Standard dballe::Query implementation.
Definition: core/query.h:34
Cursor iterating over data values.
Definition: cursor.h:77
CursorData implementation.
Definition: db/v7/cursor.h:258
Definition: db/v7/cursor.h:80
Collection of DBValue objects, indexed by wreport::Varcode.
Definition: values.h:191
Definition: db/v7/cursor.h:227
Definition: db/v7/cursor.h:36
Vertical level or layer.
Definition: types.h:624
Range of datetimes.
Definition: types.h:294
Structure used to build and execute a query, and to iterate through the results.
Definition: db/v7/cursor.h:122
Definition: db/v7/cursor.h:51
Definition: db/v7/cursor.h:64
std::deque< Row > results
Storage for the raw database results.
Definition: db/v7/cursor.h:131
Smart pointer for trace::Step objects, which calls done() when going out of scope.
Definition: db/v7/fwd.h:45
Cursor iterating over station data values.
Definition: cursor.h:66
Date and time.
Definition: types.h:164
std::shared_ptr< v7::Transaction > tr
Database to operate on.
Definition: db/v7/cursor.h:128
Cursor iterating over stations.
Definition: cursor.h:56
Structures used as input to database insert functions.
Repinfo table management used by the db module.
Container for a wreport::Var pointer, and its database ID.
Definition: value.h:71
Definition: qbuilder.h:91