Add database mutex locker and resolve "Error in my_thread_global_end()"

executeNodeQuery() and its caller are refactored since adding a QMutex pointer
to executeNodeQuery()'s arguments confuses the compiler (don't know why).

To avoid the "Error in my_thread_global_end(): X threads didn't exit" runtime
error, database connections need to be closed *on the thread that opens them*,
so we really need to open/close them on the fly instead of leaving them open.
The refactoring mentioned previously actually made this easy, fortunately. =)