Remove DBQuery class

The DBQuery class was a wrapper for a stringstream that locked and
unlocked the database in its scope. It looked like an unused variable in
many cases where queries were dynamic. As of this change, the database
class is automatically locked where necessary.

More unused code has been removed, and the Lua database functions table
size was corrected.