libdballe
6.8
|
DB-ALLe database connection. More...
#include <db.h>
Public Member Functions | |
db::Format | format () const |
Return the format of this DB. | |
Repinfo & | repinfo () |
Access the repinfo table. | |
Station & | station () |
Access the station table. | |
Context & | context () |
Access the context table. | |
Data & | data () |
Access the data table. | |
Attr & | attr () |
Access the data table. | |
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... | |
virtual 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. | |
bool | check_rep_cod (int rep_cod) |
Verify that a rep_cod is supported by the database. More... | |
int | last_station_insert_id () |
Return the ID of the last inserted station. | |
int | last_context_insert_id () |
Return the ID of the last inserted context. | |
int | get_rep_cod (const Record &rec) |
Get the report id from this record. More... | |
int | obtain_station (const Record &rec, bool can_add=true) |
int | obtain_context (const Record &rec) |
void | insert (const Record &rec, bool can_replace, bool station_can_add) |
Insert a record into the database. More... | |
int | last_station_id () const |
Return the station id for the last data that was inserted. | |
void | remove (const Record &rec) |
Remove data from the database. More... | |
void | remove_all () |
Remove all data from the database. More... | |
void | vacuum () |
Remove orphan values from the database. More... | |
std::auto_ptr< db::Cursor > | query (const Record &query, unsigned int wanted, unsigned int modifiers) |
Create and execute a database query. More... | |
std::auto_ptr< db::Cursor > | query_stations (const Record &query) |
Start a query on the station variables archive. More... | |
std::auto_ptr< db::Cursor > | query_data (const Record &rec) |
Query the database. More... | |
virtual std::auto_ptr< db::Cursor > | query_summary (const Record &rec) |
Query a summary of what the result would be for a query. More... | |
void | query_datetime_extremes (const Record &query, Record &result) |
unsigned | query_attrs (int reference_id, wreport::Varcode id_var, const db::AttrList &qcs, Record &attrs) |
Query attributes. More... | |
void | attr_insert (wreport::Varcode id_var, const Record &attrs) |
Insert new attributes into the database, reusing the reference IDs stored by the last insert. More... | |
void | attr_insert (int reference_id, wreport::Varcode id_var, const Record &attrs) |
Insert new attributes into the database. More... | |
void | attr_remove (int reference_id, wreport::Varcode id_var, const db::AttrList &qcs) |
Delete QC data for the variable `var' in record `rec' (coming from a previous dba_query) More... | |
void | import_msg (const Msg &msg, const char *repmemo, int flags) |
Import a Msg message into the DB-All.e database. More... | |
void | export_msgs (const Record &query, MsgConsumer &cons) |
Perform the query in `query', and return the results as a NULL-terminated array of dba_msg. More... | |
void | dump (FILE *out) |
Dump the entire contents of the database to an output stream. | |
![]() | |
virtual void | import_msgs (const Msgs &msgs, const char *repmemo, int flags) |
Import Msgs messages into the DB-All.e database. More... | |
Data Fields | |
db::Connection * | conn |
ODBC database connection. | |
Protected Member Functions | |
void | init_after_connect () |
void | run_sql (const char *query) |
Run a one-off SQL query. | |
void | fill_ana_layer (Msg &msg, int id_station, int id_report) |
Fill a message station info layer with information from the given station and report IDs. | |
DB (std::auto_ptr< Connection > &conn) | |
Protected Attributes | |
int | last_context_id |
db::Statement * | stm_last_insert_id |
Precompiled LAST_INSERT_ID (or equivalent) SQL statement. | |
DBALLE_SQL_C_SINT_TYPE | m_last_insert_id |
ID of the last autogenerated primary key. | |
int | _last_station_id |
struct Repinfo * | m_repinfo |
Accessors for the various parts of the database. More... | |
struct Station * | m_station |
Station information. | |
struct Context * | m_context |
Variable context. | |
struct Data * | m_data |
Variable data. | |
struct Attr * | m_attr |
Variable attributes. | |
db::Sequence * | seq_station |
Sequence accessors. More... | |
db::Sequence * | seq_context |
Context ID sequence. | |
Friends | |
class | dballe::DB |
Additional Inherited Members | |
![]() | |
static db::Format | get_default_format () |
static void | set_default_format (db::Format format) |
static std::auto_ptr< DB > | connect (const char *dsn, const char *user, const char *password) |
Start a session with DB-All.e. More... | |
static std::auto_ptr< DB > | connect_from_file (const char *pathname) |
Create from a SQLite file pathname. More... | |
static std::auto_ptr< DB > | connect_from_url (const char *url) |
Create from an url-like specification, that can be: More... | |
static std::auto_ptr< DB > | connect_memory (const std::string &arg=std::string()) |
Create an in-memory database. | |
static std::auto_ptr< DB > | connect_test () |
Start a test session with DB-All.e. More... | |
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. | |
![]() | |
static std::auto_ptr< DB > | instantiate_db (std::auto_ptr< db::Connection > &conn) |
DB-ALLe database connection.
|
virtual |
Insert new attributes into the database, reusing the reference IDs stored by the last insert.
id_var | The varcode of the variable related to the attributes to add. See vartable.h |
attrs | The record with the attributes to be added |
can_replace | If true, then existing data can be rewritten, else data can only be added. |
Implements dballe::DB.
|
virtual |
Insert new attributes into the database.
reference_id | The id (returned by Cursor::attr_reference_id()) used to refer to the variable we query |
id_var | The varcode of the variable related to the attributes to add. See vartable.h |
attrs | The record with the attributes to be added |
can_replace | If true, then existing data can be rewritten, else data can only be added. |
Implements dballe::DB.
|
virtual |
Delete QC data for the variable `var' in record `rec' (coming from a previous dba_query)
reference_id | The database id of the context related to the attributes to remove |
id_var | The varcode of the variable related to the attributes to remove. See vartable.h |
qcs | Array of WMO codes of the attributes to delete. If empty, all attributes associated to id_data will be deleted. |
Implements dballe::DB.
bool dballe::db::v5::DB::check_rep_cod | ( | int | rep_cod | ) |
Verify that a rep_cod is supported by the database.
rep_cod | The report code to verify |
|
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.
|
virtual |
Perform the query in `query', and return the results as a NULL-terminated array of dba_msg.
query | The query to perform |
cons | The MsgsConsumer that will handle the resulting messages |
Implements dballe::DB.
int dballe::db::v5::DB::get_rep_cod | ( | const Record & | rec | ) |
Get the report id from this record.
If rep_memo is specified instead, the corresponding report id is queried in the database and set as "rep_cod" in the record.
|
virtual |
Import a Msg message into the DB-All.e database.
db | The DB-All.e database to write the data into |
msg | The Msg 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.
|
virtual |
Insert a record into the database.
The reference IDs of all variables that were inserted will be stored in memory until the next insert operation. To insert attributes related to one of the variables just inserted, just call attr_insert() without the reference_id parameter.
rec | The record 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.
std::auto_ptr<db::Cursor> dballe::db::v5::DB::query | ( | const Record & | query, |
unsigned int | wanted, | ||
unsigned int | modifiers | ||
) |
Create and execute a database query.
The results are retrieved by iterating the cursor.
query | The record with the query data (see technical specifications, par. 1.6.4 "parameter output/input" |
wanted | The values wanted in output |
modifiers | Optional modifiers to ask for special query behaviours |
|
virtual |
Query attributes.
reference_id | The database id of the context related to the attributes to retrieve |
id_var | The varcode of the variable related to the attributes to retrieve. See vartable.h |
qcs | The WMO codes of the QC values requested. If it is empty, then all values are returned. |
attrs | The Record that will hold the resulting attributes |
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.
|
virtual |
Start a query on the station variables archive.
query | The record with the query data (see Keywords used by dba_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.
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.
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.
|
protected |
Sequence accessors.
They are NULL for databases such as MySQL that do not use sequences.Station ID sequence