added error logging capability for sqlite3,

which is an irrelevant digression, since it already
reports errors on calls

Maybe I will get reports if I fail to finalize a compiled
sql statement before shutting down a database connection,
but the most likely circumstance for this to happen is
on program close, when I am unlikely to be able to see
the log.
This commit is contained in:
Cheng 2023-11-13 05:54:52 +00:00
parent 3e480213cc
commit 236e59badf
No known key found for this signature in database
GPG Key ID: 571C3A9C3B9E6FCA
3 changed files with 13 additions and 3 deletions

View File

@ -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.";

View File

@ -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);
}

View File

@ -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;