libdballe  6.8
Public Member Functions | Static Public Member Functions | Static Protected Member Functions
dballe::DB Class Referenceabstract
Inheritance diagram for dballe::DB:
dballe::db::mem::DB dballe::db::v5::DB dballe::db::v6::DB

Public Member Functions

virtual db::Format format () const =0
 Return the format of this DB.
 
virtual void disappear ()=0
 Remove all our traces from the database, if applicable. More...
 
virtual void reset (const char *repinfo_file=0)=0
 Reset the database, removing all existing Db-All.e tables and re-creating them empty. More...
 
virtual void update_repinfo (const char *repinfo_file, int *added, int *deleted, int *updated)=0
 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 ()=0
 Get a mapping between rep_memo and their priorities.
 
virtual void insert (const Record &rec, bool can_replace, bool station_can_add)=0
 Insert a record into the database. More...
 
virtual int last_station_id () const =0
 Return the station id for the last data that was inserted.
 
virtual void remove (const Record &rec)=0
 Remove data from the database. More...
 
virtual void remove_all ()=0
 Remove all data from the database. More...
 
virtual void vacuum ()=0
 Perform database cleanup operations. More...
 
virtual std::auto_ptr< db::Cursorquery_stations (const Record &query)=0
 Start a query on the station variables archive. More...
 
virtual std::auto_ptr< db::Cursorquery_data (const Record &rec)=0
 Query the database. More...
 
virtual std::auto_ptr< db::Cursorquery_summary (const Record &rec)=0
 Query a summary of what the result would be for a query. More...
 
virtual unsigned query_attrs (int reference_id, wreport::Varcode id_var, const db::AttrList &qcs, Record &attrs)=0
 Query attributes. More...
 
virtual void attr_insert (wreport::Varcode id_var, const Record &attrs)=0
 Insert new attributes into the database, reusing the reference IDs stored by the last insert. More...
 
virtual void attr_insert (int reference_id, wreport::Varcode id_var, const Record &attrs)=0
 Insert new attributes into the database. More...
 
virtual void attr_remove (int reference_id, wreport::Varcode id_var, const db::AttrList &qcs)=0
 Delete QC data for the variable `var' in record `rec' (coming from a previous dba_query) More...
 
virtual void import_msg (const Msg &msg, const char *repmemo, int flags)=0
 Import a Msg message into the DB-All.e database. More...
 
virtual void import_msgs (const Msgs &msgs, const char *repmemo, int flags)
 Import Msgs messages into the DB-All.e database. More...
 
virtual void export_msgs (const Record &query, MsgConsumer &cons)=0
 Perform the query in `query', and return the results as a NULL-terminated array of dba_msg. More...
 
virtual void dump (FILE *out)=0
 Dump the entire contents of the database to an output stream.
 

Static Public Member Functions

static db::Format get_default_format ()
 
static void set_default_format (db::Format format)
 
static std::auto_ptr< DBconnect (const char *dsn, const char *user, const char *password)
 Start a session with DB-All.e. More...
 
static std::auto_ptr< DBconnect_from_file (const char *pathname)
 Create from a SQLite file pathname. More...
 
static std::auto_ptr< DBconnect_from_url (const char *url)
 Create from an url-like specification, that can be: More...
 
static std::auto_ptr< DBconnect_memory (const std::string &arg=std::string())
 Create an in-memory database.
 
static std::auto_ptr< DBconnect_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 Protected Member Functions

static std::auto_ptr< DBinstantiate_db (std::auto_ptr< db::Connection > &conn)
 

Member Function Documentation

virtual void dballe::DB::attr_insert ( wreport::Varcode  id_var,
const Record attrs 
)
pure virtual

Insert new attributes into the database, reusing the reference IDs stored by the last insert.

Parameters
id_varThe varcode of the variable related to the attributes to add. See vartable.h
attrsThe record with the attributes to be added
can_replaceIf true, then existing data can be rewritten, else data can only be added.

Implemented in dballe::db::v6::DB, dballe::db::v5::DB, and dballe::db::mem::DB.

virtual void dballe::DB::attr_insert ( int  reference_id,
wreport::Varcode  id_var,
const Record attrs 
)
pure virtual

Insert new attributes into the database.

Parameters
reference_idThe id (returned by Cursor::attr_reference_id()) used to refer to the variable we query
id_varThe varcode of the variable related to the attributes to add. See vartable.h
attrsThe record with the attributes to be added
can_replaceIf true, then existing data can be rewritten, else data can only be added.

Implemented in dballe::db::v6::DB, dballe::db::v5::DB, and dballe::db::mem::DB.

virtual void dballe::DB::attr_remove ( int  reference_id,
wreport::Varcode  id_var,
const db::AttrList &  qcs 
)
pure virtual

Delete QC data for the variable `var' in record `rec' (coming from a previous dba_query)

Parameters
reference_idThe id (returned by Cursor::attr_reference_id()) used to refer to the variable we query
id_varThe varcode of the variable related to the attributes to remove. See vartable.h
qcsArray of WMO codes of the attributes to delete. If empty, all attributes associated to id_data will be deleted.

Implemented in dballe::db::v6::DB, dballe::db::v5::DB, and dballe::db::mem::DB.

static std::auto_ptr<DB> dballe::DB::connect ( const char *  dsn,
const char *  user,
const char *  password 
)
static

Start a session with DB-All.e.

Parameters
dsnThe ODBC DSN of the database to use
userThe user name to use to connect to the DSN
passwordThe password to use to connect to the DSN. To specify an empty password, pass "" or NULL
Returns
The new DB object
static std::auto_ptr<DB> dballe::DB::connect_from_file ( const char *  pathname)
static

Create from a SQLite file pathname.

Parameters
pathnameThe pathname to a SQLite file
static std::auto_ptr<DB> dballe::DB::connect_from_url ( const char *  url)
static

Create from an url-like specification, that can be:

sqlite:[//]foo.sqlite odbc://[user[:pass]@]dsn test:[//]

Parameters
urlThe url-like connection descriptor
static std::auto_ptr<DB> dballe::DB::connect_test ( )
static

Start a test session with DB-All.e.

Take information from the environment (

See also
dba_db_create_from_env) and default to ./test.sqlite if nothing is specified.
virtual void dballe::DB::disappear ( )
pure virtual

Remove all our traces from the database, if applicable.

After this has been called, all other DB methods except for reset() will fail.

Implemented in dballe::db::v6::DB, dballe::db::v5::DB, and dballe::db::mem::DB.

virtual void dballe::DB::export_msgs ( const Record query,
MsgConsumer cons 
)
pure virtual

Perform the query in `query', and return the results as a NULL-terminated array of dba_msg.

Parameters
queryThe query to perform
consThe MsgsConsumer that will handle the resulting messages

Implemented in dballe::db::v6::DB, dballe::db::v5::DB, and dballe::db::mem::DB.

virtual void dballe::DB::import_msg ( const Msg msg,
const char *  repmemo,
int  flags 
)
pure virtual

Import a Msg message into the DB-All.e database.

Parameters
dbThe DB-All.e database to write the data into
msgThe Msg containing the data to import
repmemoReport mnemonic to which imported data belong. If NULL is passed, then it will be chosen automatically based on the message type.
flagsCustomise different aspects of the import process. It is a bitmask of the various DBA_IMPORT_* macros.

Implemented in dballe::db::v6::DB, dballe::db::v5::DB, and dballe::db::mem::DB.

virtual void dballe::DB::import_msgs ( const Msgs msgs,
const char *  repmemo,
int  flags 
)
virtual

Import Msgs messages into the DB-All.e database.

Parameters
dbThe DB-All.e database to write the data into
msgsThe Msgs containing the data to import
repmemoReport mnemonic to which imported data belong. If NULL is passed, then it will be chosen automatically based on the message type.
flagsCustomise different aspects of the import process. It is a bitmask of the various DBA_IMPORT_* macros.
virtual void dballe::DB::insert ( const Record rec,
bool  can_replace,
bool  station_can_add 
)
pure 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.

Parameters
recThe record to insert.
can_replaceIf true, then existing data can be rewritten, else data can only be added.
station_can_addIf 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.

Implemented in dballe::db::v6::DB, dballe::db::v5::DB, and dballe::db::mem::DB.

static bool dballe::DB::is_url ( const char *  str)
static

Return TRUE if the string looks like a DB URL.

Parameters
strThe string to test
Returns
true if it looks like a URL, else false
virtual unsigned dballe::DB::query_attrs ( int  reference_id,
wreport::Varcode  id_var,
const db::AttrList &  qcs,
Record attrs 
)
pure virtual

Query attributes.

Parameters
reference_idThe id (returned by Cursor::attr_reference_id()) used to refer to the variable we query
id_varThe varcode of the variable related to the attributes to retrieve. See vartable.h
qcsThe WMO codes of the QC values requested. If it is empty, then all values are returned.
attrsThe Record that will hold the resulting attributes
Returns
Number of attributes returned in attrs

Implemented in dballe::db::v6::DB, dballe::db::v5::DB, and dballe::db::mem::DB.

virtual std::auto_ptr<db::Cursor> dballe::DB::query_data ( const Record rec)
pure virtual

Query the database.

When multiple values per variable are present, the results will be presented in increasing order of priority.

Parameters
queryThe record with the query data (see technical specifications, par. 1.6.4 "parameter output/input")
Returns
The cursor to use to iterate over the results

Implemented in dballe::db::v6::DB, dballe::db::v5::DB, and dballe::db::mem::DB.

virtual std::auto_ptr<db::Cursor> dballe::DB::query_stations ( const Record query)
pure 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.

Parameters
queryThe record with the query data (see Keywords used by dba_record)
Returns
The cursor to use to iterate over the results

Implemented in dballe::db::v6::DB, dballe::db::v5::DB, and dballe::db::mem::DB.

virtual std::auto_ptr<db::Cursor> dballe::DB::query_summary ( const Record rec)
pure virtual

Query a summary of what the result would be for a query.

Parameters
queryThe record with the query data (see technical specifications, par. 1.6.4 "parameter output/input")
Returns
The cursor to use to iterate over the results. The results are the same as query_data, except that no context_id, datetime and value are provided, so it only gives all the available combinations of data contexts.

Implemented in dballe::db::v6::DB, dballe::db::v5::DB, and dballe::db::mem::DB.

virtual void dballe::DB::remove ( const Record rec)
pure virtual

Remove data from the database.

Parameters
recThe record with the query data (see technical specifications, par. 1.6.4 "parameter output/input") to select the items to be deleted

Implemented in dballe::db::v6::DB, dballe::db::v5::DB, and dballe::db::mem::DB.

virtual void dballe::DB::remove_all ( )
pure virtual

Remove all data from the database.

This is faster than remove() with an empty record, and unlike reset() it preserves existing report information.

Implemented in dballe::db::v6::DB, dballe::db::v5::DB, and dballe::db::mem::DB.

virtual void dballe::DB::reset ( const char *  repinfo_file = 0)
pure virtual

Reset the database, removing all existing Db-All.e tables and re-creating them empty.

Parameters
repinfo_fileThe 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.

Implemented in dballe::db::v6::DB, dballe::db::v5::DB, and dballe::db::mem::DB.

virtual void dballe::DB::update_repinfo ( const char *  repinfo_file,
int *  added,
int *  deleted,
int *  updated 
)
pure virtual

Update the repinfo table in the database, with the data found in the given file.

Parameters
repinfo_fileThe 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.
Return values
addedThe number of repinfo entries that have been added
deletedThe number of repinfo entries that have been deleted
updatedThe number of repinfo entries that have been updated

Implemented in dballe::db::v6::DB, dballe::db::v5::DB, and dballe::db::mem::DB.

virtual void dballe::DB::vacuum ( )
pure virtual

Perform database cleanup operations.

Orphan values are currently:

  • context values for which no data exists
  • station values for which no context exists

Depending on database size, this routine can take a few minutes to execute.

Implemented in dballe::db::v6::DB, dballe::db::v5::DB, and dballe::db::mem::DB.


The documentation for this class was generated from the following file: