OpenFCST: The open-source Fuel Cell Simulation Toolbox
|
This class is for interfacing with SQL databases, *for the purpose of accessing and storing simulation results. More...
#include <fcst_db.h>
Public Member Functions | |
FCSTdatabase () | |
Constructor. | |
virtual | ~FCSTdatabase () |
Destructor. | |
bool | connect (const std::string &db_path) |
Function for connecting to SQL database. | |
bool | connect () |
Function for connecting to default SQL database, located at fcst_root/main_db. | |
bool | disconnect () |
Function for disconnecting to SQL database. | |
bool | has_data (const std::string &model_name, const DatabaseOC &OC) |
Function for testing if db that you are connected to has data for a given model and operating conditions. | |
bool | has_data (const std::string &model_name, const DatabaseOC &OC, const double &tolerance) |
Function for testing if db that you are connected to has data for a given model and operating conditions. | |
std::vector< std::vector < double > > | get_data (const std::string &model_name, const DatabaseOC &OC) |
Function for getting numerical information for a given model and operating conditions. | |
std::vector< std::vector < double > > | get_data (const std::string &model_name, const DatabaseOC &OC, const double &tolerance) |
Function for getting numerical information for a given model and operating conditions. | |
std::vector< std::vector < double > > | get_data (const std::string &model_name, const DatabaseOC &OC, const double &tolerance, const std::string &orderby) |
Function for getting numerical information for a given model and operating conditions. | |
bool | commit_data (const std::string &model_name, const DatabaseOC &OC, const std::vector< std::string > &column_names, const std::vector< std::vector< double >> &data) |
Function for committing numerical information for a given model and operating conditions. | |
std::vector< std::vector < std::string > > | request (const std::string &sqlCmd) |
Wrapper Function for performing direct SQL requests. | |
bool | clear_data (const std::string &model_name, const DatabaseOC &OC) |
Function for clearing data for a given model and operating conditions. | |
Private Member Functions | |
std::string | make_new_head_entry (const std::string &model_name, const DatabaseOC &OC) |
bool | create_table (const std::string &table_name, const std::vector< std::string > &column_names) |
bool | fill_empty_table (const std::string &table_name, const std::vector< std::vector< double >> &data, const std::vector< std::string > &column_names) |
std::string | find_table (const std::string &model_name, const DatabaseOC &OC) |
std::string | find_table (const std::string &model_name, const DatabaseOC &OC, const double &tolerance) |
bool | find_matching_head_term (const std::vector< std::string > &OC, const std::vector< std::string > &head_line, const double &tolerance) |
bool | request_no_callback (const std::string &sqlCmd) |
bool | request (const std::string &sqlCmd, const bool &useCallBack, int lockCounter=3) |
Static Private Member Functions | |
static int | callback (void *db_, int argc, char **argv, char **azColName) |
Private Attributes | |
sqlite3 * | db |
bool | connected |
std::string | db_path |
std::vector< std::vector < std::string > > | temp |
This class is for interfacing with SQL databases, *for the purpose of accessing and storing simulation results.
FcstUtilities::FCSTdatabase::FCSTdatabase | ( | ) |
Constructor.
|
virtual |
Destructor.
|
inlinestaticprivate |
References AppFrame::argc, db, and temp.
bool FcstUtilities::FCSTdatabase::clear_data | ( | const std::string & | model_name, |
const DatabaseOC & | OC | ||
) |
Function for clearing data for a given model and operating conditions.
Takes model name and operating conditions as arguments. OC is a 2d array (vector vector) in which for a given line the first element is the operating condition name and the second element is the value.
Returns true if data is successfully deleted.
See Unit test "testCommitData" for usage demo.
bool FcstUtilities::FCSTdatabase::commit_data | ( | const std::string & | model_name, |
const DatabaseOC & | OC, | ||
const std::vector< std::string > & | column_names, | ||
const std::vector< std::vector< double >> & | data | ||
) |
Function for committing numerical information for a given model and operating conditions.
Takes model name, operating conditions, data column titles, and data as arguments. OC is a 2d array (vector vector) in which for a given line the first element is the operating condition name and the second element is the value. Column_names is a list of column that pertains to the numerical data stored in argument data. Data is a 2d array (vector vector) of doubles containing the data we whish to store.
Returns an empty vector(vector(double)) if no data exists.
See Unit test "testCommitData" for usage demo.
bool FcstUtilities::FCSTdatabase::connect | ( | const std::string & | db_path | ) |
Function for connecting to SQL database.
Takes database file path as argument. Returns true if connection successful
bool FcstUtilities::FCSTdatabase::connect | ( | ) |
Function for connecting to default SQL database, located at fcst_root/main_db.
Returns true if connection successful
|
private |
bool FcstUtilities::FCSTdatabase::disconnect | ( | ) |
Function for disconnecting to SQL database.
Returns true if disconnection successful
|
private |
|
private |
|
private |
|
private |
std::vector<std::vector<double> > FcstUtilities::FCSTdatabase::get_data | ( | const std::string & | model_name, |
const DatabaseOC & | OC | ||
) |
Function for getting numerical information for a given model and operating conditions.
Takes model name and operating conditions as arguments. OC is an object of DatabaseOC type.
N.b: returns an potentially unordered (by rows) list of results. See third overloading of this function.
Returns an empty vector(vector(double)) if no data exists.
See Unit test "testGetData" for usage demo.
std::vector<std::vector<double> > FcstUtilities::FCSTdatabase::get_data | ( | const std::string & | model_name, |
const DatabaseOC & | OC, | ||
const double & | tolerance | ||
) |
Function for getting numerical information for a given model and operating conditions.
Takes model name, operating conditions, and a tolerance as arguments. OC is an object of DatabaseOC type. Differences in operating condition values will be compared with provided tolerance (0.0 - 1.0).
N.b: returns an potentially unordered (by rows) list of results. See third overloading of this function.
Returns an empty vector(vector(double)) if no data exists.
See Unit test "testGetData" for usage demo.
std::vector<std::vector<double> > FcstUtilities::FCSTdatabase::get_data | ( | const std::string & | model_name, |
const DatabaseOC & | OC, | ||
const double & | tolerance, | ||
const std::string & | orderby | ||
) |
Function for getting numerical information for a given model and operating conditions.
Takes model name, operating conditions, orderby string,and a tolerance as arguments. OC is an object of DatabaseOC type. Differences in operating condition values will be compared with provided tolerance (0.0 - 1.0). Orderby is the name of the column that the results will be ordered by before being returned.
Returns an empty vector(vector(double)) if no data exists.
See Unit test "testGetData" for usage demo.
bool FcstUtilities::FCSTdatabase::has_data | ( | const std::string & | model_name, |
const DatabaseOC & | OC | ||
) |
Function for testing if db that you are connected to has data for a given model and operating conditions.
Takes model name and operating conditions as arguments. OC is an object of DatabaseOC type.
Returns true if data exists.
See Unit test "testHasData" for usage demo.
bool FcstUtilities::FCSTdatabase::has_data | ( | const std::string & | model_name, |
const DatabaseOC & | OC, | ||
const double & | tolerance | ||
) |
Function for testing if db that you are connected to has data for a given model and operating conditions.
Takes model name, operating conditions, and a tolerance as arguments. OC is an object of DatabaseOC type. Differences in operating condition values will be compared with provided tolerance (0.0 - 1.0). Returns true if data exists.
See Unit test "testHasData" for usage demo.
|
private |
std::vector<std::vector<std::string> > FcstUtilities::FCSTdatabase::request | ( | const std::string & | sqlCmd | ) |
Wrapper Function for performing direct SQL requests.
Takes a SQL statement as argument. Returns the results of the request in a 2d array (vector vector) of strings.
Note: If you don't know SQL then this is probably not the function for you, try another.
See Unit test "testRequest" for usage demo.
|
private |
|
private |
|
private |
|
private |
Referenced by callback().
|
private |
|
private |
Referenced by callback().