core: Add a @_logquery decorator to log SQL statements