diff options
author | Dominick Allen <djallen@librehumanitas.org> | 2024-10-15 20:56:26 -0500 |
---|---|---|
committer | Dominick Allen <djallen@librehumanitas.org> | 2024-10-15 20:56:26 -0500 |
commit | f3ac764684c64fbdd2094853a80b23e570cd5d9c (patch) | |
tree | 3b7f64480a1247455d28e23b6bb5ff63303c9170 /include/fud_sqlite.hpp | |
parent | 71976e927cca43b970cb659c03fd6908c352ea3d (diff) |
Conver to using static constructors for string, sqlite, files.
Diffstat (limited to 'include/fud_sqlite.hpp')
-rw-r--r-- | include/fud_sqlite.hpp | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/include/fud_sqlite.hpp b/include/fud_sqlite.hpp index d879ed0..c56b4a1 100644 --- a/include/fud_sqlite.hpp +++ b/include/fud_sqlite.hpp @@ -21,6 +21,7 @@ #include <fud_result.hpp> #include <fud_status.hpp> #include <fud_string.hpp> +#include <memory> #include <sqlite3.h> namespace fud { @@ -34,11 +35,19 @@ enum class SqliteOpenMode : int ReadWriteCreate = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE }; +class SqliteErrorMsg; + +class SqliteDb; +using SqliteDbResult = Result<SqliteDb, FudStatus>; + class SqliteDb { + private: + constexpr SqliteDb() = default; + public: - SqliteDb(const String& name, SqliteOpenMode mode, int extraFlags = 0); + static SqliteDbResult make(const String& name, SqliteOpenMode mode, int extraFlags = 0); - SqliteDb(const char* name, SqliteOpenMode mode, int extraFlags = 0); + static SqliteDbResult make(const char* cStrName, SqliteOpenMode mode, int extraFlags = 0); SqliteDb(const SqliteDb&) = delete; @@ -58,7 +67,7 @@ class SqliteDb { const String& statement, int (*callback)(void*, int, char**, char**), void* context, - String* errorMessage); + std::unique_ptr<SqliteErrorMsg> errorMessage); constexpr int errorCode() { @@ -70,16 +79,15 @@ class SqliteDb { return m_dbHandle; } - // private methods private: - void initialize(); + // private methods + FudStatus initialize(); [[nodiscard]] int open(); Result<SqliteStatement, FudStatus> prepare(const String& sql); // private data members - private: String m_name{}; bool m_nameValid{false}; @@ -133,6 +141,22 @@ class SqliteStatement { sqlite3_stmt* m_preparedStatement{nullptr}; }; +class SqliteErrorMsg { + public: + constexpr SqliteErrorMsg() = default; + explicit constexpr SqliteErrorMsg(char* errorMsg) : m_errorMsg{errorMsg} + { + } + SqliteErrorMsg(const SqliteErrorMsg&) = delete; + SqliteErrorMsg(SqliteErrorMsg&& rhs) noexcept; + ~SqliteErrorMsg(); + SqliteErrorMsg& operator=(const SqliteErrorMsg&) = delete; + SqliteErrorMsg& operator=(SqliteErrorMsg&& rhs) noexcept; + + private: + char* m_errorMsg{nullptr}; +}; + } // namespace fud #endif |