diff --git a/src/ISqlit3Impl.cpp b/src/ISqlit3Impl.cpp index 61a0c8f..a079b5c 100644 --- a/src/ISqlit3Impl.cpp +++ b/src/ISqlit3Impl.cpp @@ -59,7 +59,13 @@ static auto error_message(int rc, sqlite3* pdb) { return std::string("Sqlite3 Error: ") + sqlite3_errmsg(pdb) + ". Sqlite3 error number=" + std::to_string(rc); } -void sqlite3_init() { +void sqlite3_init(void (*SqliteErrorLogCallback_ptr)(void*, int, const char*)) { + // We are setting up a global Error logging callback for all database connections + // Maybe in future we will need separate call back for each database connection, + // Which sqlite also supports, but do not need to think about it now. + if (sqlite3_config(SQLITE_CONFIG_LOG, SqliteErrorLogCallback_ptr, nullptr) != SQLITE_OK) { + throw MyException("huh, cannot log?"); + } if (sqlite3_initialize() != SQLITE_OK) { errorCode = 7; szError = "Fatal Error: Sqlite library did not init."; diff --git a/src/ISqlite3.h b/src/ISqlite3.h index ba6529b..799dce8 100644 --- a/src/ISqlite3.h +++ b/src/ISqlite3.h @@ -87,7 +87,7 @@ ISqlite3* Sqlite3_create(const char*);//The actual run time object is the derive Icompiled_sql* sqlite3_prepare(ISqlite3*, const char *);//The actual run time object is the derived class //Which lives a symbol space that is kept separate from wxWidgets C++ space -void sqlite3_init(); +void sqlite3_init(void (*SqliteErrorLogCallback_ptr)(void*, int, const char*)); extern "C" { int sqlite3_shutdown(void); } diff --git a/src/frame.cpp b/src/frame.cpp index 312df65..fba1b37 100644 --- a/src/frame.cpp +++ b/src/frame.cpp @@ -132,6 +132,10 @@ void RecursiveCreateDirectory(wxFileName& fn){ } } +static void SqliteErrorLogCallback(void* pArg, int iErrCode, const char* zMsg) { + wxLogMessage(wxT("SqliteLogMessage (%d) %s\n"), iErrCode, zMsg); +} + // main frame ctor Frame::Frame(const wxString& wxs) : wxFrame(nullptr, myID_MAINFRAME, wxs, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, wxs), @@ -142,7 +146,7 @@ Frame::Frame(const wxString& wxs) assert(singletonFrame == nullptr); singletonFrame = this; SetIcon(wxICON(AAArho)); - sqlite3_init(); + sqlite3_init(&SqliteErrorLogCallback); if (sodium_init() < 0) { szError = "Fatal Error: Encryption library did not init."; errorCode = 6;