libdballe  6.8
Data Structures | Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes | Friends
dballe::db::mem::DB Class Reference

DB-ALLe database connection. More...

#include <db.h>

Inheritance diagram for dballe::db::mem::DB:
dballe::DB

Data Structures

struct  VarID
 Store information about the database ID of a variable. More...
 

Public Member Functions

 DB (const std::string &arg)
 
db::Format format () const
 Return the format of this DB.
 
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 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.
 
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::Cursorquery_stations (const Record &query)
 Start a query on the station archive. More...
 
std::auto_ptr< db::Cursorquery_data (const Record &rec)
 Query the database. More...
 
std::auto_ptr< db::Cursorquery_summary (const Record &rec)
 Query a summary of what the result would be for a query. More...
 
unsigned query_attrs (int id_data, 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 id_data, wreport::Varcode id_var, const Record &attrs)
 Insert new attributes into the database. More...
 
void attr_remove (int id_data, 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.
 
- Public Member Functions inherited from dballe::DB
virtual void import_msgs (const Msgs &msgs, const char *repmemo, int flags)
 Import Msgs messages into the DB-All.e database. More...
 

Data Fields

Memdb memdb
 In-memory database backend.
 
Repinfo repinfo
 

Protected Member Functions

void raw_query_stations (const Record &rec, memdb::Results< memdb::Station > &res)
 Query stations, returning a list of station IDs.
 
void raw_query_station_data (const Record &rec, memdb::Results< memdb::StationValue > &res)
 Query station data, returning a list of Value IDs.
 
void raw_query_data (const Record &rec, memdb::Results< memdb::Value > &res)
 Query data, returning a list of Value IDs.
 

Protected Attributes

std::string serialization_dir
 
size_t m_last_station_id
 
std::vector< VarIDlast_insert_varids
 Store database variable IDs for all last inserted variables.
 

Friends

class dballe::DB
 

Additional Inherited Members

- Static Public Member Functions inherited from dballe::DB
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 inherited from dballe::DB
static std::auto_ptr< DBinstantiate_db (std::auto_ptr< db::Connection > &conn)
 

Detailed Description

DB-ALLe database connection.

Member Function Documentation

void dballe::db::mem::DB::attr_insert ( wreport::Varcode  id_var,
const Record attrs 
)
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.

Implements dballe::DB.

void dballe::db::mem::DB::attr_insert ( int  reference_id,
wreport::Varcode  id_var,
const Record attrs 
)
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.

Implements dballe::DB.

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

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

Parameters
id_dataThe database id of the lev_tr related to the attributes to remove
id_varThe varcode of the variable related to the attributes to remove. See vartable.h (ignored)
qcsArray of WMO codes of the attributes to delete. If empty, all attributes associated to id_data will be deleted.

Implements dballe::DB.

void dballe::db::mem::DB::disappear ( )
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.

void dballe::db::mem::DB::export_msgs ( const Record query,
MsgConsumer cons 
)
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

Implements dballe::DB.

void dballe::db::mem::DB::import_msg ( const Msg msg,
const char *  repmemo,
int  flags 
)
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.

Implements dballe::DB.

void dballe::db::mem::DB::insert ( const Record rec,
bool  can_replace,
bool  station_can_add 
)
virtual

Insert a record into the database.

In a record with the same phisical situation already exists, the function fails.

Parameters
recThe record to insert.
can_replaceIf true, then existing data can be rewritten, else data can only be added.
station_can_addIf true, then it is allowed to add new station records to the database. Otherwise, data can be added only by reusing existing ones.

Implements dballe::DB.

unsigned dballe::db::mem::DB::query_attrs ( int  id_data,
wreport::Varcode  id_var,
const db::AttrList &  qcs,
Record attrs 
)
virtual

Query attributes.

Parameters
id_dataThe database id of the data related to the attributes to retrieve
id_varThe varcode of the variable related to the attributes to retrieve. See vartable.h (ignored)
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

Implements dballe::DB.

std::auto_ptr<db::Cursor> dballe::db::mem::DB::query_data ( const Record rec)
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

Implements dballe::DB.

std::auto_ptr<db::Cursor> dballe::db::mem::DB::query_stations ( const Record query)
virtual

Start a query on the station archive.

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

Implements dballe::DB.

std::auto_ptr<db::Cursor> dballe::db::mem::DB::query_summary ( const Record rec)
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.

Implements dballe::DB.

void dballe::db::mem::DB::remove ( const Record rec)
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

Implements dballe::DB.

void dballe::db::mem::DB::remove_all ( )
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.

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

Reset the database, removing all existing DBALLE 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.

Implements dballe::DB.

void dballe::db::mem::DB::update_repinfo ( const char *  repinfo_file,
int *  added,
int *  deleted,
int *  updated 
)
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 entryes that have been added
deletedThe number of repinfo entryes that have been deleted
updatedThe number of repinfo entryes that have been updated

Implements dballe::DB.

void dballe::db::mem::DB::vacuum ( )
virtual

Remove orphan values from the database.

Orphan values are currently:

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

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

Implements dballe::DB.


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