Database: factorized lastqueryerror()