|
libdballe 5.10
|
DB-ALLe database connection. More...
#include <db.h>
Public Member Functions | |
| void | connect (const char *dsn, const char *user, const char *password) |
| Start a session with DB-All.e. | |
| void | connect_generic (const char *config) |
| Start a session with DB-All.e. | |
| void | connect_from_file (const char *pathname) |
| Create from a SQLite file pathname. | |
| void | connect_from_url (const char *url) |
| Create from an url-like specification, that can be: | |
| void | connect_test () |
| Start a test session with DB-All.e. | |
| db::Repinfo & | repinfo () |
| Access the repinfo table. | |
| db::Station & | station () |
| Access the station table. | |
| db::Context & | context () |
| Access the context table. | |
| db::Data & | data () |
| Access the data table. | |
| db::Attr & | attr () |
| Access the data table. | |
| void | reset (const char *repinfo_file=0) |
| Reset the database, removing all existing DBALLE tables and re-creating them empty. | |
| 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. | |
| int | rep_cod_from_memo (const char *memo) |
| Get the report code from a report mnemonic. | |
| const std::string & | rep_memo_from_cod (int rep_cod) |
| Get the report mnemonic from a report code. | |
| bool | check_rep_cod (int rep_cod) |
| Verify that a rep_cod is supported by the database. | |
| 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 (Record &rec) |
| Get the report id from this record. | |
| int | obtain_station (Record &rec, bool can_add=true) |
| int | obtain_context (Record &rec) |
| void | insert (Record &rec, bool can_replace, bool station_can_add) |
| Insert a record into the database. | |
| void | remove (const Record &rec) |
| Remove data from the database. | |
| void | remove_orphans () |
| Remove orphan values from the database. | |
| std::auto_ptr< db::Cursor > | query (const Record &query, unsigned int wanted, unsigned int modifiers) |
| Create and execute a database query. | |
| std::auto_ptr< db::Cursor > | query_stations (const Record &query) |
| Start a query on the station archive. | |
| std::auto_ptr< db::Cursor > | query_data (const Record &rec) |
| Query the database. | |
| unsigned | query_attrs (int id_context, wreport::Varcode id_var, const std::vector< wreport::Varcode > &qcs, Record &attrs) |
| Query attributes. | |
| void | attr_insert_or_replace (int id_context, wreport::Varcode id_var, const Record &attrs, bool can_replace) |
| Insert new attributes into the database. | |
| void | attr_insert (int id_context, wreport::Varcode id_var, const Record &attrs) |
| Insert new attributes into the database. | |
| void | attr_insert_new (int id_context, wreport::Varcode id_var, const Record &attrs) |
| Insert new attributes into the database. | |
| void | attr_remove (int id_context, wreport::Varcode id_var, const std::vector< wreport::Varcode > &qcs) |
| Delete QC data for the variable `var' in record `rec' (coming from a previous dba_query) | |
| void | import_msg (const Msg &msg, const char *repmemo, int flags) |
| Import a Msg message into the DB-All.e database. | |
| void | import_msgs (const Msgs &msgs, const char *repmemo, int flags) |
| Import Msgs messages into the DB-All.e database. | |
| 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. | |
| void | dump (FILE *out) |
| Dump the entire contents of the database to an output stream. | |
Static Public Member Functions | |
| static bool | is_url (const char *str) |
| Return TRUE if the string looks like a DB URL. | |
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 | drop_table_if_exists (const char *name) |
| Delete a table in the database if it exists, otherwise do nothing. | |
| void | drop_sequence_if_exists (const char *name) |
| Delete a sequence in the database if it exists, otherwise do nothing. | |
| 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. | |
Protected Attributes | |
| 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. | |
| struct db::Repinfo * | m_repinfo |
| Accessors for the various parts of the database. | |
| struct db::Station * | m_station |
| Station information. | |
| struct db::Context * | m_context |
| Variable context. | |
| struct db::Data * | m_data |
| Variable data. | |
| struct db::Attr * | m_attr |
| Variable attributes. | |
| db::Sequence * | seq_station |
| Sequence accessors. | |
| db::Sequence * | seq_context |
| Context ID sequence. | |
DB-ALLe database connection.
| void dballe::DB::attr_insert | ( | int | id_context, |
| wreport::Varcode | id_var, | ||
| const Record & | attrs | ||
| ) |
Insert new attributes into the database.
If the same attribute exists for the same data, it is overwritten
| id_context | The database id of the context related to the attributes to 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 |
| void dballe::DB::attr_insert_new | ( | int | id_context, |
| wreport::Varcode | id_var, | ||
| const Record & | attrs | ||
| ) |
Insert new attributes into the database.
If the same attribute exists for the same data, the function fails.
| id_context | The database id of the context related to the attributes to 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 |
| void dballe::DB::attr_insert_or_replace | ( | int | id_context, |
| wreport::Varcode | id_var, | ||
| const Record & | attrs, | ||
| bool | can_replace | ||
| ) |
Insert new attributes into the database.
| id_context | The database id of the context related to the attributes to 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. |
| void dballe::DB::attr_remove | ( | int | id_context, |
| wreport::Varcode | id_var, | ||
| const std::vector< wreport::Varcode > & | qcs | ||
| ) |
Delete QC data for the variable `var' in record `rec' (coming from a previous dba_query)
| id_context | 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. |
| bool dballe::DB::check_rep_cod | ( | int | rep_cod | ) |
Verify that a rep_cod is supported by the database.
| rep_cod | The report code to verify |
| void dballe::DB::connect | ( | const char * | dsn, |
| const char * | user, | ||
| const char * | password | ||
| ) |
Start a session with DB-All.e.
| dsn | The ODBC DSN of the database to use |
| user | The user name to use to connect to the DSN |
| password | The password to use to connect to the DSN. To specify an empty password, pass "" or NULL |
| db | The dba_db handle returned by the function |
| void dballe::DB::connect_from_file | ( | const char * | pathname | ) |
Create from a SQLite file pathname.
| pathname | The pathname to a SQLite file |
| void dballe::DB::connect_from_url | ( | const char * | url | ) |
Create from an url-like specification, that can be:
sqlite:[//]foo.sqlite odbc://[user[:pass]@]dsn test:[//]
| url | The url-like connection descriptor |
| void dballe::DB::connect_generic | ( | const char * | config | ) |
Start a session with DB-All.e.
| config | The string with the configuration to use to start the connection. This is passed as is to SQLDriverConnect, so see ODBC documentation for its format. |
| void dballe::DB::connect_test | ( | ) |
Start a test session with DB-All.e.
Take information from the environment (
| void dballe::DB::export_msgs | ( | const Record & | query, |
| MsgConsumer & | cons | ||
| ) |
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 |
| int dballe::DB::get_rep_cod | ( | 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.
| void dballe::DB::import_msg | ( | const Msg & | msg, |
| const char * | repmemo, | ||
| int | flags | ||
| ) |
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. |
| void dballe::DB::import_msgs | ( | const Msgs & | msgs, |
| const char * | repmemo, | ||
| int | flags | ||
| ) |
Import Msgs messages into the DB-All.e database.
| db | The DB-All.e database to write the data into |
| msgs | The Msgs 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. |
| void dballe::DB::insert | ( | Record & | rec, |
| bool | can_replace, | ||
| bool | station_can_add | ||
| ) |
Insert a record into the database.
In a record with the same phisical situation already exists, the function fails.
ana_id and context_id will be set in the record at the end of this function.
| 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 true, then it is allowed to add new station records to the database. Otherwise, data can be added only by reusing existing ones. |
| static bool dballe::DB::is_url | ( | const char * | str | ) | [static] |
Return TRUE if the string looks like a DB URL.
| str | The string to test |
| std::auto_ptr<db::Cursor> dballe::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 |
| unsigned dballe::DB::query_attrs | ( | int | id_context, |
| wreport::Varcode | id_var, | ||
| const std::vector< wreport::Varcode > & | qcs, | ||
| Record & | attrs | ||
| ) |
Query attributes.
| id_context | 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 |
| std::auto_ptr<db::Cursor> dballe::DB::query_data | ( | const Record & | rec | ) |
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") |
| std::auto_ptr<db::Cursor> dballe::DB::query_stations | ( | const Record & | query | ) |
Start a query on the station archive.
| query | The record with the query data (see Keywords used by dba_record) |
| void dballe::DB::remove | ( | const Record & | rec | ) |
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 |
| void dballe::DB::remove_orphans | ( | ) |
Remove orphan values from the database.
Orphan values are currently:
Depending on database size, this routine can take a few minutes to execute.
| void dballe::DB::reset | ( | const char * | repinfo_file = 0 | ) |
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. |
| void dballe::DB::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.
| 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 |
struct db::Repinfo* dballe::DB::m_repinfo [protected] |
Accessors for the various parts of the database.
db::Sequence* dballe::DB::seq_station [protected] |
Sequence accessors.
They are NULL for databases such as MySQL that do not use sequences. Station ID sequence
1.7.4