Trading System API  3.0
Library for Simulating and Deploying Trading and Investment Strategies
tsa::data_base Class Referenceabstract

Base class for all other database classes such as: More...

#include <TSADBBase.h>

Inheritance diagram for tsa::data_base:
tsa::object tsa::fast::database tsa::postgres::database tsa::sqlite::database

Public Member Functions

 data_base (void)
 Constructor.
 
virtual ~data_base (void)
 Destructor.
 
void copy_table_from (data_base &source_db, const std::string &source_table_name, const std::string &target_table_name, const table_copy_params &copy_prop=table_copy_params())
 Copies a table, potentially from one database to another, according to the given table_copy_properties object, which by default copies the entire table. See class table_copy_properties for more details. More...
 
virtual void create_series_table (const std::string &table_name, const tsa::column_defs &columns)=0
 Creates a new series table. A series table is a table that has a timestamp as first column. Recall that the timestamp is implicit to all series tables and must not be given as part of the columns definition. More...
 
virtual bool drop_series_table (const std::string &table_name)=0
 ??????? drop_table
 
void import (const file_import_rules__obsolete &import_properties)
 Imports records from a text file according to the given import properties. See class file_import_properties for more information. More...
 
void print_table_info (const std::string &table_name, std::ostream &stream)
 Prints basic information about the table. More...
 
virtual void series_append (const std::string &table_name, const tsa::mem_table &m_table)=0
 Appends the records from the given m_table to a database table. This operation will fail if there is overal in the range of timestamps, or if the column structure does not match. More...
 
bool series_columns_match (const std::string &table_name, const tsa::mem_table &m_table)
 Returns true if a database table has an identical column structure to a given mem_table. More...
 
virtual void series_load (const std::string &table_name, tsa::mem_table &mtable, const date_time &from_timestamp, size_t num_records)=0
 Loads a number of series records from a given database table into a mem_table (memory based table) object. More...
 
virtual date_time series_table_closest_timestamp_LOE (const date_time &target, const std::string &table_name)=0
 Returns the record timestamp that is closest to, but lower than, the given target timestamp. More...
 
virtual tsa::column_defs series_table_column_defs (const std::string &table_name)=0
 Returns the column definition structure. More...
 
virtual date_time series_table_first_timestamp (const std::string &table_name)=0
 Returns the timestamp of the first record in the table. More...
 
virtual date_time series_table_last_timestamp (const std::string &table_name)=0
 Returns the timestamp of the last records in the table. More...
 
virtual bool table_exists (const std::string &table_name) const =0
 Returns true if a database table exists. More...
 
virtual bool table_has_data (const std::string &table_name)=0
 Returns true if the table has records, false if empty. More...
 
virtual int64_t table_record_count (const std::string &table_name)=0
 Returns the number of records in the table. More...
 
virtual bool table_record_count_is_known (void) const =0
 Returns true if the database system knows the size (record count) of a table at all times, or whether it needs to iterate through the table to calculate the size. In the native fast::database knows the table size at all times, whereas SQL databases need to launch the 'select count(*)' command. More...
 
virtual void truncate_series_table (const std::string &table_name, const date_time &new_max_timestamp=date_time::min)=0
 Truncates a database table by deleting all records higher than a given new_max_timestamp. More...
 
virtual std::string type (void) const =0
 Returns the 'type' of the database as a string, such as "sqlite", "postgresql" or the native "fast". More...
 
- Public Member Functions inherited from tsa::object
 object (void)
 Constructor.
 
virtual ~object (void)
 Destructor.
 
const char * class_name (void) const
 Returns the class name as returned by the 'Real Time Type Information' (RTTI) mechanism. More...
 
bool has_same_class_as (const object &other) const
 Returns true if self has the same type as other object. More...
 

Detailed Description

Base class for all other database classes such as:

Member Function Documentation

void tsa::data_base::copy_table_from ( data_base source_db,
const std::string source_table_name,
const std::string target_table_name,
const table_copy_params copy_prop = table_copy_params() 
)

Copies a table, potentially from one database to another, according to the given table_copy_properties object, which by default copies the entire table. See class table_copy_properties for more details.

Parameters
[in,out]source_dbSource database.
source_table_nameName of the source table.
target_table_nameName of the target table.
copy_propThe property of the copy operation.
virtual void tsa::data_base::create_series_table ( const std::string table_name,
const tsa::column_defs columns 
)
pure virtual

Creates a new series table. A series table is a table that has a timestamp as first column. Recall that the timestamp is implicit to all series tables and must not be given as part of the columns definition.

Parameters
table_nameThe name of the new series table.
columnsThe columnar structure.

Implemented in tsa::sqlite::database, tsa::fast::database, and tsa::postgres::database.

void tsa::data_base::import ( const file_import_rules__obsolete import_properties)

Imports records from a text file according to the given import properties. See class file_import_properties for more information.

Parameters
import_propertiesThe import properties.
void tsa::data_base::print_table_info ( const std::string table_name,
std::ostream &  stream 
)

Prints basic information about the table.

Parameters
table_nameName of the table.
[in,out]streamThe stream.
virtual void tsa::data_base::series_append ( const std::string table_name,
const tsa::mem_table m_table 
)
pure virtual

Appends the records from the given m_table to a database table. This operation will fail if there is overal in the range of timestamps, or if the column structure does not match.

Parameters
table_nameName of the target databse table.
m_tableThe memory based table.

Implemented in tsa::fast::database, tsa::sqlite::database, and tsa::postgres::database.

bool tsa::data_base::series_columns_match ( const std::string table_name,
const tsa::mem_table m_table 
)

Returns true if a database table has an identical column structure to a given mem_table.

Parameters
table_nameName of the database table.
m_tableThe memory based table.
Returns
true if it succeeds, false if it fails.
virtual void tsa::data_base::series_load ( const std::string table_name,
tsa::mem_table mtable,
const date_time from_timestamp,
size_t  num_records 
)
pure virtual

Loads a number of series records from a given database table into a mem_table (memory based table) object.

Parameters
table_nameName of the database table.
[in,out]mtableThe mem_table.
from_timestampThe timestamp of the first record to load.
num_recordsThe number of records to load.

Implemented in tsa::fast::database, tsa::sqlite::database, and tsa::postgres::database.

virtual date_time tsa::data_base::series_table_closest_timestamp_LOE ( const date_time target,
const std::string table_name 
)
pure virtual

Returns the record timestamp that is closest to, but lower than, the given target timestamp.

Parameters
targetThe target timestamp.
table_nameName of the table.
Returns
A date_time.

Implemented in tsa::fast::database, tsa::sqlite::database, and tsa::postgres::database.

virtual tsa::column_defs tsa::data_base::series_table_column_defs ( const std::string table_name)
pure virtual

Returns the column definition structure.

Parameters
table_nameName of the table.
Returns
A tsa::column_defs.

Implemented in tsa::fast::database, tsa::sqlite::database, and tsa::postgres::database.

virtual date_time tsa::data_base::series_table_first_timestamp ( const std::string table_name)
pure virtual

Returns the timestamp of the first record in the table.

Parameters
table_nameName of the table.
Returns
A date_time.

Implemented in tsa::fast::database, tsa::sqlite::database, and tsa::postgres::database.

virtual date_time tsa::data_base::series_table_last_timestamp ( const std::string table_name)
pure virtual

Returns the timestamp of the last records in the table.

Parameters
table_nameName of the table.
Returns
A date_time.

Implemented in tsa::fast::database, tsa::sqlite::database, and tsa::postgres::database.

virtual bool tsa::data_base::table_exists ( const std::string table_name) const
pure virtual

Returns true if a database table exists.

Parameters
table_nameName of the database table.
Returns
true if it exists.

Implemented in tsa::fast::database, tsa::sqlite::database, and tsa::postgres::database.

virtual bool tsa::data_base::table_has_data ( const std::string table_name)
pure virtual

Returns true if the table has records, false if empty.

Parameters
table_nameName of the table.
Returns
true if it succeeds, false if it fails.

Implemented in tsa::fast::database, tsa::sqlite::database, and tsa::postgres::database.

virtual int64_t tsa::data_base::table_record_count ( const std::string table_name)
pure virtual

Returns the number of records in the table.

Parameters
table_nameName of the table.
Returns
An int64_t.

Implemented in tsa::fast::database, tsa::sqlite::database, and tsa::postgres::database.

virtual bool tsa::data_base::table_record_count_is_known ( void  ) const
pure virtual

Returns true if the database system knows the size (record count) of a table at all times, or whether it needs to iterate through the table to calculate the size. In the native fast::database knows the table size at all times, whereas SQL databases need to launch the 'select count(*)' command.

Returns
bool.

Implemented in tsa::fast::database, tsa::sqlite::database, and tsa::postgres::database.

virtual void tsa::data_base::truncate_series_table ( const std::string table_name,
const date_time new_max_timestamp = date_time::min 
)
pure virtual

Truncates a database table by deleting all records higher than a given new_max_timestamp.

Parameters
table_nameName of the table.
new_max_timestampThe new maximum record timestamp.

Implemented in tsa::fast::database, tsa::sqlite::database, and tsa::postgres::database.

virtual std::string tsa::data_base::type ( void  ) const
pure virtual

Returns the 'type' of the database as a string, such as "sqlite", "postgresql" or the native "fast".

Returns
A std::string.

Implemented in tsa::sqlite::database, tsa::fast::database, and tsa::postgres::database.