14 #ifndef TSA_DATABASE__INCLUDED 15 #define TSA_DATABASE__INCLUDED 22 #include "TSADBCore.h" 23 #include "TSALargeFile.h" 24 #include "TSASimBaseSeries.h" 25 #include "TSAPriceBar.h" 26 #include "TSASeriesTemplate.h" 27 #include "TSAStreams.h" 29 #include "TSADataDef.h" 30 #include "TSADBBase.h" 31 #include "TSADatabaseImp.h" 119 tsa_declare_testable;
120 friend class table_imp_ref;
121 friend class table_imp;
124 friend class table_reader;
126 class db_file_creator {
129 db_file_creator(
void);
135 enum Result { success, table_does_not_exist, table_is_opened };
137 db_page_file m_page_file;
138 db_storage_manager m_storage_man;
139 std::map<table_imp_ref*, table_imp_ref*> m_table_ptr_map;
142 std::map<std::string, table_imp*> m_name_to_table_map;
143 size_t __get_next_page_num_to_write(
void)
const;
147 static bool invalid_shutdown;
149 db_page_file* get_page_file_ptr(
void);
150 size_t get_page_size(
void)
const;
152 table_imp_ref get_table_object(
const std::string&);
153 void save_table_object(
const table_imp&);
154 size_t get_open_table_count(
void)
const;
156 static bool can_open_file_exclusively(
const os::path& path);
258 static bool exists(
const os::path& db_path);
266 static void remove(
const os::path& db_path);
270 static void create_db_files(
const std::string& name,
const os::path& directory,
bool bReplace =
false);
340 virtual bool drop_series_table(
const std::string& table_name)
override;
347 virtual bool table_exists(
const std::string& name)
const override;
355 bool table_exists_with_data(
const std::string& table_name);
371 bool table_is_writeable(
const std::string& name)
const;
394 size_t table_count(
void)
const;
408 void table_names(std::vector<std::string>& table_name_arr)
const;
427 bool GetTableTimeSpanInfo(
const std::string& tableName,
size_t& numberOfRecords,
429 table_metrics get_table_metrics(
const std::string& tableName);
438 virtual bool table_has_data(
const std::string& table_name)
override;
442 const date_time& from_timestamp,
size_t num_records)
override;
445 virtual bool table_record_count_is_known(
void)
const;
446 virtual int64_t table_record_count(
const std::string& table_name);
476 bool replace =
false,
bool error_as_exception =
true);
489 void print_table_report(std::ostream& stream);
495 void print_table_names(std::ostream&);
507 void print_table(
const std::string& name, std::ostream& stream,
size_t FPPrecision = 8,
520 void save_table_html(
const std::string& name,
const os::path& path,
size_t FPPrecision = 8,
542 const date_time& end, std::ostream& stream);
552 void print_table_vertical(
const std::string& name, std::ostream& stream,
579 size_t width = 70,
size_t height = 20,
595 void print_hlc_graph(
const std::string& table, std::ostream& stream,
596 size_t width = 70,
size_t height = 20,
600 std::ostream& S, TablePrinter& tablePrinter,
605 db_storage_manager* get_db_storage_manager(
void);
606 db_record* create_record_object(
const std::string& data_def_name);
609 bool data_def_exists(
const std::string& name)
const;
613 void delete_unused_data_def(
void);
616 void data_def_names_arr(std::vector<std::string>& schemaNameArray)
const;
617 bool data_def_in_use(
const std::string& schemaName)
const;
618 void print_data_def_report(std::ostream& stream);
621 size_t db_page_count(
void)
const;
622 size_t db_free_page_count(
void)
const;
627 void register_table_imp_ptr(table_imp_ref*);
628 void unregister_table_imp_ptr(table_imp_ref*);
629 void close_table(table_imp* ptable);
630 table_imp* LoadCorePtr(
unsigned table_id);
631 void force_close_table_no_exception(table_imp* pSeries);
632 Result load_table(table_imp*&,
const std::string& table_name);
633 table_imp* load_table(
const std::string& table_name);
634 void print_db_table_info(std::ostream& Stream);
636 void VerifyTableHasOHLCV_Fields(
const std::string& tableName);
637 void verify_table_has_PV_fields(
const std::string& tableName);
638 void verify_has_ohlcv_fields(
const std::string& tableName);
643 void convert_tick_to_1min(
const std::string& in_table_name,
647 void convert_tick_to_sec(
const std::string& in_table_name,
648 size_t seconds_per_bar,
const std::string& out_table_name);
650 void convert_1min_to_multi_min(
const std::string& in_table_name,
651 size_t minutes_per_bar,
const std::string& out_table_name);
659 void convert_tick_to_multi_tick(
const std::string& in_table_name,
660 size_t numTicksPerBar,
const std::string& targetTable,
663 void convert_tick_to_volume(
const std::string& source_table,
664 size_t volumePerBar,
const std::string& out_table_name);
669 void import_daily_data(
const std::string& tableName,
678 const std::string& timeFormatString =
"hh:mm:ss.f",
679 char sep =
',',
bool fixDuplicateTime =
false);
688 bool delete_existing_table =
false;
691 bool timestamp_one_field =
true;
692 char datetime_separator =
' ';
694 char separator =
'\n';
695 bool fix_duplicate_timestamp =
false;
699 void import_file(
const import_info& info);
Definition: TSATypeDef.h:106
Utility class to manipulate file system paths. This class is intended to fulfil the requirements of t...
Definition: TSAOS.h:36
class series is a template class representing a sequence of values.
Definition: TSASeriesProxy.h:24
Namespace for the 'Trading System API' library.
Definition: original1.TSA3Core.cpp:20
const size_t print_no_limit
flag to print without limiting the number of lines printed.
Definition: TSATypeDef.h:78
Class for managing native timeseries database files. Extremely high speed data access.
Definition: TSADatabase.h:118
Base class for all other database classes such as:
Definition: TSADBBase.h:47
Create the database if it does not already exist.
Definition: TSADatabase.h:44
missing_table_flag_type
Values that represent missing table flag types.
Definition: TSATypeDef.h:111
Defines the columnar structure of a table. Each column has a name, data type and field size...
Definition: TSADataDef.h:88
Raise an exception if database does not already exist.
Definition: TSADatabase.h:45
Parent class for 'in-stream adaptors'. in_stream object rely on adaptors for access to underlying dat...
Definition: TSAStreams.h:52
Abstract base class for delegates of class out_stream.
Definition: TSAStreams.h:553
replace_flag_type
Replace / no-replace flag used by various objects.
Definition: TSATypeDef.h:105
static const date_time min
Constant representing the smallest allowed date_time.
Definition: TSATime.h:449
Definition: TSATypeDef.h:112
variant objects can represent values of different types.
Definition: TSAVariant.h:140
Replace existing target if it already exists.
Definition: TSAStreams.h:533
open_db_flag_type
Enumeration of Database constructor flags. Multiple flags can be combined via operator|.
Definition: TSADatabase.h:43
static const date_time max
Constant representing the largest allowed date_time.
Definition: TSATime.h:452
Clears all data in the database upon opening the database.
Definition: TSADatabase.h:46
Represents a database table in fast::database.
Definition: TSADBTable.h:41
Class representing a gregorian-date and time-of-day combination. The time component has microsecond r...
Definition: TSATime.h:428
int64_t identifier_t
type for ID's
Definition: TSATypeDef.h:117
Class mem_table represents a memory based table. mem_table objects can be used in strategies both for...
Definition: TSAMemTable.h:48
open_db_flag_type operator|(open_db_flag_type a, open_db_flag_type b)
Allows multiple fast::database constructor flags to be combined.
Definition: TSADatabase.cpp:40