libdballe
7.29
|
DB-ALLe database connection, database format V6. More...
#include <db.h>
Public Member Functions | |
db::Format | format () const |
Return the format of this DB. | |
v6::Driver & | driver () |
Access the backend DB driver. | |
v6::Repinfo & | repinfo () |
Access the repinfo table. | |
v6::Station & | station () |
Access the station table. | |
v6::LevTr & | lev_tr () |
Access the lev_tr table. | |
v6::LevTrCache & | lev_tr_cache () |
Access the lev_tr cache. | |
v6::DataV6 & | data () |
Access the data table. | |
v6::AttrV6 & | attr () |
Access the data table. | |
std::unique_ptr < dballe::Transaction > | transaction () override |
Begin a transaction on this database, and return a Transaction object that can be used to commit it. | |
void | disappear () |
Remove all our traces from the database, if applicable. More... | |
void | reset (const char *repinfo_file=0) |
Reset the database, removing all existing DBALLE tables and re-creating them empty. More... | |
void | delete_tables () |
Delete all the DB-ALLe tables from the database. | |
void | update_repinfo (const char *repinfo_file, int *added, int *deleted, int *updated) |
Update the repinfo table in the database, with the data found in the given file. More... | |
std::map< std::string, int > | get_repinfo_priorities () |
Get a mapping between rep_memo and their priorities. | |
int | rep_cod_from_memo (const char *memo) |
Get the report code from a report mnemonic. | |
void | insert_station_data (dballe::Transaction &transaction, StationValues &vals, bool can_replace, bool station_can_add) override |
Insert station values into the database. More... | |
void | insert_data (dballe::Transaction &transaction, DataValues &vals, bool can_replace, bool station_can_add) override |
Insert data values into the database. More... | |
void | remove_station_data (dballe::Transaction &transaction, const Query &query) override |
Remove data from the database. More... | |
void | remove (dballe::Transaction &transaction, const Query &query) |
Remove data from the database. More... | |
void | remove_all (dballe::Transaction &transaction) |
Remove all data from the database. More... | |
void | vacuum () |
Remove orphan values from the database. More... | |
std::unique_ptr < db::CursorStation > | query_stations (const Query &query) |
Start a query on the station variables archive. More... | |
std::unique_ptr < db::CursorStationData > | query_station_data (const Query &query) override |
Query the station variables in the database. More... | |
std::unique_ptr< db::CursorData > | query_data (const Query &query) |
Query the database. More... | |
std::unique_ptr < db::CursorSummary > | query_summary (const Query &query) |
Query a summary of what the result would be for a query. More... | |
void | attr_query_station (int data_id, std::function< void(std::unique_ptr< wreport::Var >)> &&dest) override |
Query attributes on a station value. More... | |
void | attr_query_data (int data_id, std::function< void(std::unique_ptr< wreport::Var >)> &&dest) override |
Query attributes on a data value. More... | |
void | attr_insert_station (dballe::Transaction &transaction, int data_id, const Values &attrs) override |
Insert new attributes on a station value. More... | |
void | attr_insert_data (dballe::Transaction &transaction, int data_id, const Values &attrs) override |
Insert new attributes on a data value. More... | |
void | attr_remove_station (dballe::Transaction &transaction, int data_id, const db::AttrList &qcs) override |
Delete attributes from a station value. More... | |
void | attr_remove_data (dballe::Transaction &transaction, int data_id, const db::AttrList &qcs) override |
Delete attributes from a data value. More... | |
bool | is_station_variable (int data_id, wreport::Varcode varcode) override |
Check if this varcode and data_id correspond to a station variable. More... | |
void | import_msg (dballe::Transaction &transaction, const Message &msg, const char *repmemo, int flags) override |
Import a Message into the DB-All.e database. More... | |
bool | export_msgs (dballe::Transaction &transaction, const Query &query, std::function< bool(std::unique_ptr< Message > &&)> dest) override |
Perform the query in `query', and send the results to dest. More... | |
void | dump (FILE *out) |
Dump the entire contents of the database to an output stream. | |
![]() | |
void | insert_station_data (StationValues &vals, bool can_replace, bool station_can_add) |
Insert station values into the database. More... | |
void | insert_data (DataValues &vals, bool can_replace, bool station_can_add) |
Insert data values into the database. More... | |
void | remove_station_data (const Query &query) |
Remove data from the database. More... | |
void | remove (const Query &query) |
Remove data from the database. More... | |
void | remove_all () |
Remove all data from the database. More... | |
void | attr_insert_station (int data_id, const Values &attrs) |
Insert new attributes on a station value. More... | |
void | attr_insert_data (int data_id, const Values &attrs) |
Insert new attributes on a data value. More... | |
void | attr_remove_station (int data_id, const db::AttrList &attrs) |
Delete attributes from a station value. More... | |
void | attr_remove_data (int data_id, const db::AttrList &attrs) |
Delete attributes from a data value. More... | |
void | import_msg (const Message &msg, const char *repmemo, int flags) |
Import a Message into the DB-All.e database. More... | |
void | import_msgs (const Messages &msgs, const char *repmemo, int flags) |
Import Messages into the DB-All.e database. More... | |
virtual void | import_msgs (dballe::Transaction &transaction, const Messages &msgs, const char *repmemo, int flags) |
Import Messages into the DB-All.e database. More... | |
bool | export_msgs (const Query &query, std::function< bool(std::unique_ptr< Message > &&)> dest) |
Perform the query in `query', and send the results to dest. More... | |
virtual void | print_info (FILE *out) |
Print informations about the database to the given output stream. | |
Public Attributes | |
dballe::sql::Connection * | conn |
Database connection. | |
Trace | trace |
Database query tracing. | |
bool | explain_queries = false |
True if we print an EXPLAIN trace of all queries to stderr. | |
Protected Member Functions | |
void | init_after_connect () |
DB (std::unique_ptr< dballe::sql::Connection > conn) | |
int | obtain_station (const dballe::Station &st, bool can_add=true) |
Protected Attributes | |
v6::Driver * | m_driver |
SQL driver backend. | |
struct v6::Repinfo * | m_repinfo |
Accessors for the various parts of the database. More... | |
struct v6::Station * | m_station |
Station information. | |
struct v6::LevTr * | m_lev_tr |
Level/timerange information. | |
struct v6::LevTrCache * | m_lev_tr_cache |
Level/timerange cache. | |
struct v6::DataV6 * | m_data |
Variable data. | |
struct v6::AttrV6 * | m_attr |
Variable attributes. | |
Friends | |
class | dballe::DB |
Additional Inherited Members | |
![]() | |
static db::Format | get_default_format () |
static void | set_default_format (db::Format format) |
static std::unique_ptr< DB > | connect_from_file (const char *pathname) |
Create from a SQLite file pathname. More... | |
static std::unique_ptr< DB > | connect_from_url (const char *url) |
Create from an url-like specification, as described in doc/fapi_connect.md. More... | |
static std::unique_ptr< DB > | connect_memory (const std::string &arg=std::string()) |
Create an in-memory database. | |
static std::unique_ptr< DB > | connect_test () |
Start a test session with DB-All.e. More... | |
static std::unique_ptr< DB > | create (std::unique_ptr< sql::Connection > conn) |
Create a database from an open Connection. | |
static bool | is_url (const char *str) |
Return TRUE if the string looks like a DB URL. More... | |
static const char * | default_repinfo_file () |
Return the default repinfo file pathname. | |
DB-ALLe database connection, database format V6.
|
overridevirtual |
Insert new attributes on a data value.
transaction | The current active transaction. |
data_id | The id (returned by Cursor::attr_reference_id()) used to refer to the value |
attrs | The attributes to be added |
Implements dballe::DB.
|
overridevirtual |
Insert new attributes on a station value.
transaction | The current active transaction. |
data_id | The id (returned by Cursor::attr_reference_id()) used to refer to the value |
attrs | The attributes to be added |
Implements dballe::DB.
|
overridevirtual |
Query attributes on a data value.
data_id | The id (returned by Cursor::attr_reference_id()) used to refer to the value |
dest | The function that will be called on each resulting attribute |
Implements dballe::DB.
|
overridevirtual |
Query attributes on a station value.
data_id | The id (returned by Cursor::attr_reference_id()) used to refer to the value |
dest | The function that will be called on each resulting attribute |
Implements dballe::DB.
|
overridevirtual |
Delete attributes from a data value.
transaction | The current active transaction. |
data_id | The id (returned by Cursor::attr_reference_id()) used to refer to the value |
attrs | Array of WMO codes of the attributes to delete. If empty, all attributes associated to the value will be deleted. |
Implements dballe::DB.
|
overridevirtual |
Delete attributes from a station value.
transaction | The current active transaction. |
data_id | The id (returned by Cursor::attr_reference_id()) used to refer to the value |
attrs | Array of WMO codes of the attributes to delete. If empty, all attributes associated to the value will be deleted. |
Implements dballe::DB.
|
virtual |
Remove all our traces from the database, if applicable.
After this has been called, all other DB methods except for reset() will fail.
Implements dballe::DB.
|
overridevirtual |
Perform the query in `query', and send the results to dest.
Return false from dest to interrupt the query.
transaction | The current active transaction. |
query | The query to perform |
dest | The function that will handle the resulting messages |
Implements dballe::DB.
|
overridevirtual |
Import a Message into the DB-All.e database.
transaction | The current active transaction. |
msg | The Message containing the data to import |
repmemo | Report mnemonic to which imported data belong. If NULL is passed, then it will be chosen automatically based on the message type. |
flags | Customise different aspects of the import process. It is a bitmask of the various DBA_IMPORT_* macros. |
Implements dballe::DB.
|
overridevirtual |
Insert data values into the database.
The IDs of the station andl all variables that were inserted will be stored in vals.
transaction | The current active transaction. |
vals | The values to insert. |
can_replace | If true, then existing data can be rewritten, else data can only be added. |
station_can_add | If false, it will not create a missing station record, and only data for existing stations can be added. If true, then if we are inserting data for a station that does not yet exists in the database, it will be created. |
Implements dballe::DB.
|
overridevirtual |
Insert station values into the database.
The IDs of the station andl all variables that were inserted will be stored in vals.
transaction | The current active transaction. |
vals | The values to insert. |
can_replace | If true, then existing data can be rewritten, else data can only be added. |
station_can_add | If false, it will not create a missing station record, and only data for existing stations can be added. If true, then if we are inserting data for a station that does not yet exists in the database, it will be created. |
Implements dballe::DB.
|
overridevirtual |
Check if this varcode and data_id correspond to a station variable.
This is used only to implement attr_* functions to be used when this information is not known. A database for which this information is not relevant (for example, in v6 databases there is a single ID space for station and data variable) can return any arbitrary value, since later they will be ignored.
This should disappear once client APIs start making a distinction between attributes in station variables and attributes on data variables.
Implements dballe::DB.
|
virtual |
Query the database.
When multiple values per variable are present, the results will be presented in increasing order of priority.
query | The record with the query data (see technical specifications, par. 1.6.4 "parameter output/input") |
Implements dballe::DB.
|
overridevirtual |
Query the station variables in the database.
When multiple values per variable are present, the results will be presented in increasing order of priority.
query | The record with the query data (see technical specifications, par. 1.6.4 "parameter output/input") |
Implements dballe::DB.
|
virtual |
Start a query on the station variables archive.
The cursor will iterate over unique lat, lon, ident triples, and will contain all station vars. If a station var exists twice on two different networks, only one will be present: the one of the network with the highest priority.
query | The record with the query data (see Keywords used by dballe::Record) |
Implements dballe::DB.
|
virtual |
Query a summary of what the result would be for a query.
query | The record with the query data (see technical specifications, par. 1.6.4 "parameter output/input") |
Implements dballe::DB.
|
virtual |
Remove data from the database.
transaction | The current active transaction. |
rec | The record with the query data (see technical specifications, par. 1.6.4 "parameter output/input") to select the items to be deleted |
Implements dballe::DB.
|
virtual |
Remove all data from the database.
This is faster than remove() with an empty record, and unlike reset() it preserves existing report information.
transaction | The current active transaction. |
Implements dballe::DB.
|
overridevirtual |
Remove data from the database.
transaction | The current active transaction. |
query | The record with the query data (see technical specifications, par. 1.6.4 "parameter output/input") to select the items to be deleted |
Implements dballe::DB.
|
virtual |
Reset the database, removing all existing DBALLE tables and re-creating them empty.
repinfo_file | The name of the CSV file with the report type information data to load. The file is in CSV format with 6 columns: report code, mnemonic id, description, priority, descriptor, table A category. If repinfo_file is NULL, then the default of /etc/dballe/repinfo.csv is used. |
Implements dballe::DB.
|
virtual |
Update the repinfo table in the database, with the data found in the given file.
repinfo_file | The name of the CSV file with the report type information data to load. The file is in CSV format with 6 columns: report code, mnemonic id, description, priority, descriptor, table A category. If repinfo_file is NULL, then the default of /etc/dballe/repinfo.csv is used. |
added | The number of repinfo entryes that have been added |
deleted | The number of repinfo entryes that have been deleted |
updated | The number of repinfo entryes that have been updated |
Implements dballe::DB.
|
virtual |
Remove orphan values from the database.
Orphan values are currently:
Depending on database size, this routine can take a few minutes to execute.
Implements dballe::DB.
|
protected |
Accessors for the various parts of the database.