summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/fud_sqlite.hpp7
-rw-r--r--source/fud_sqlite.cpp29
2 files changed, 26 insertions, 10 deletions
diff --git a/include/fud_sqlite.hpp b/include/fud_sqlite.hpp
index 4f4c60f..8dcdea8 100644
--- a/include/fud_sqlite.hpp
+++ b/include/fud_sqlite.hpp
@@ -70,8 +70,13 @@ class SqliteDb {
FudStatus exec(
const String& statement,
int (*callback)(void*, int, char**, char**),
+ void* context);
+
+ FudStatus exec(
+ const String& statement,
+ int (*callback)(void*, int, char**, char**),
void* context,
- Option<SqliteErrorMsg&>& errorMessage);
+ SqliteErrorMsg& errorMessage);
template <typename T>
FudStatus bind(SqliteStatement& statement, int index, T value);
diff --git a/source/fud_sqlite.cpp b/source/fud_sqlite.cpp
index c607b37..f7193bf 100644
--- a/source/fud_sqlite.cpp
+++ b/source/fud_sqlite.cpp
@@ -138,29 +138,40 @@ int SqliteDb::open()
return sqlite3_open_v2(m_name.c_str(), &m_dbHandle, static_cast<int>(m_mode) | m_extraFlags, nullptr);
}
+FudStatus SqliteDb::exec(const String& statement, int (*callback)(void*, int, char**, char**), void* context)
+{
+ if (!valid()) {
+ return FudStatus::ObjectInvalid;
+ }
+
+ if (!statement.utf8Valid()) {
+ return FudStatus::Utf8Invalid;
+ }
+
+ m_errorCode = sqlite3_exec(m_dbHandle, statement.c_str(), callback, context, nullptr);
+
+ return m_errorCode == SQLITE_OK ? FudStatus::Success : FudStatus::Failure;
+}
+
FudStatus SqliteDb::exec(
const String& statement,
int (*callback)(void*, int, char**, char**),
void* context,
- // NOLINTNEXTLINE(performance-copy-param-value)
- Option<SqliteErrorMsg&>& errorMessage)
+ SqliteErrorMsg& errorMessage)
{
if (!valid()) {
return FudStatus::ObjectInvalid;
}
+ char* errorMsgPtr = nullptr;
+
if (!statement.utf8Valid()) {
return FudStatus::Utf8Invalid;
}
- char* errorMsgPtr = nullptr;
- char** errorMsgPtrAddress = errorMessage.isNone() ? nullptr : &errorMsgPtr;
-
- m_errorCode = sqlite3_exec(m_dbHandle, statement.c_str(), callback, context, errorMsgPtrAddress);
+ m_errorCode = sqlite3_exec(m_dbHandle, statement.c_str(), callback, context, &errorMsgPtr);
- if (errorMessage.hasValue()) {
- errorMessage.value().setMessage(errorMsgPtr);
- }
+ errorMessage.setMessage(errorMsgPtr);
return m_errorCode == SQLITE_OK ? FudStatus::Success : FudStatus::Failure;
}