Refactoring include out of the source folder, added in an SQL manager#7
Refactoring include out of the source folder, added in an SQL manager#7
Conversation
|
There was a problem hiding this comment.
Pull request overview
This PR reorganizes project headers into a top-level include/ directory and introduces a small SqlManager abstraction to centralize the initial market-data query.
Changes:
- Move/introduce headers under
include/and update build include paths accordingly. - Add
SqlManagerand wire it intomainto fetch initialPriceData. - Adjust local run script behavior (environment sourcing removed; DB endpoint changed).
Reviewed changes
Copilot reviewed 8 out of 22 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| source/sqlManager.cpp | Implements a centralized initial SQL query + execution wrapper. |
| include/sqlManager.hpp | Declares the new SqlManager API and default limit. |
| source/main.cpp | Switches initial query callsite to SqlManager. |
| source/jsonParser.cpp | Adds file header comment block. |
| include/jsonParser.hpp | Declares JsonParser public API in new include path. |
| include/databaseConnection.hpp | Introduces/relocates DB connection interface into include/. |
| include/utilities/base64.hpp | Introduces/relocates Base64 + Utilities declarations into include/. |
| include/configManager.hpp | Introduces/relocates ConfigManager into include/. |
| include/serviceA.hpp | Introduces/relocates ServiceA into include/. |
| include/models/priceData.hpp | Adds required <chrono> include for timestamp. |
| include/models/trade.hpp | Introduces/relocates Trade model into include/. |
| include/trading/tradeManager.hpp | Introduces/relocates TradeManager interface into include/. |
| include/trading_definitions/*.hpp | Introduces/relocates JSON-mapped config structs into include/. |
| include/trading_definitions.hpp | Adds umbrella header for trading definitions. |
| scripts/run.sh | Changes environment sourcing and hardcodes DB endpoint IP. |
| CMakeLists.txt | Updates include directories to use top-level include/. |
| backtesting-engine-cpp.xcodeproj/project.pbxproj | Adds include/ group and sqlManager sources to Xcode project. |
Comments suppressed due to low confidence (1)
source/main.cpp:41
executeQuery()returns an empty vector on errors, but the code immediately indexespriceData[0]without checking. If the DB connection/query fails (or returns no rows), this will be an out-of-bounds access and crash. Add an explicit empty-check (and handle the failure case) before usingpriceData[0].
std::vector<PriceData> priceData = SqlManager::getInitialPriceData(db);
// Convert timestamp to readable format for debugging
auto timeT = std::chrono::system_clock::to_time_t(priceData[0].timestamp);
std::cout << "Timestamp: " << std::put_time(std::localtime(&timeT), "%Y-%m-%d %H:%M:%S") << std::endl;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| std::string SqlManager::getBaseQuery() { | ||
| return "SELECT * FROM EURUSD LIMIT " + std::to_string(DEFAULT_LIMIT) + ";"; |
There was a problem hiding this comment.
getBaseQuery() hardcodes the table/symbol (EURUSD) and the row limit, even though configuration includes a SYMBOLS field. To make SqlManager reusable (and avoid having to change code for different symbols/limits), consider taking symbol and limit as parameters (or reading them from the parsed configuration).
| std::string SqlManager::getBaseQuery() { | |
| return "SELECT * FROM EURUSD LIMIT " + std::to_string(DEFAULT_LIMIT) + ";"; | |
| #include <cstdlib> | |
| #include <string> | |
| namespace { | |
| std::string getConfiguredSymbol() { | |
| const char* symbols = std::getenv("SYMBOLS"); | |
| if (symbols == nullptr || *symbols == '\0') { | |
| return "EURUSD"; | |
| } | |
| std::string configuredSymbols(symbols); | |
| std::size_t separator = configuredSymbols.find(','); | |
| std::string symbol = configuredSymbols.substr(0, separator); | |
| std::size_t first = symbol.find_first_not_of(" \t"); | |
| if (first == std::string::npos) { | |
| return "EURUSD"; | |
| } | |
| std::size_t last = symbol.find_last_not_of(" \t"); | |
| return symbol.substr(first, last - first + 1); | |
| } | |
| int getConfiguredLimit() { | |
| const char* configuredLimit = std::getenv("SQL_LIMIT"); | |
| if (configuredLimit == nullptr || *configuredLimit == '\0') { | |
| return DEFAULT_LIMIT; | |
| } | |
| char* end = nullptr; | |
| long parsedLimit = std::strtol(configuredLimit, &end, 10); | |
| if (end == configuredLimit || *end != '\0' || parsedLimit <= 0) { | |
| return DEFAULT_LIMIT; | |
| } | |
| return static_cast<int>(parsedLimit); | |
| } | |
| } // namespace | |
| std::string SqlManager::getBaseQuery() { | |
| return "SELECT * FROM " + getConfiguredSymbol() + " LIMIT " + std::to_string(getConfiguredLimit()) + ";"; |
| std::string SqlManager::getBaseQuery() { | ||
| return "SELECT * FROM EURUSD LIMIT " + std::to_string(DEFAULT_LIMIT) + ";"; | ||
| } | ||
|
|
||
| std::vector<PriceData> SqlManager::getInitialPriceData(const DatabaseConnection& db) { |
There was a problem hiding this comment.
There are XCTest-based tests for other components, but nothing covers the new SqlManager behavior (e.g., the generated base query / default limit). Adding a small unit test would help catch regressions as the query logic evolves.
|


No description provided.