def error_in_query(q, task, log):
    """call after every q.exec_ to check for errors;
    logs error and problematic query,
    returns error message for QMessagebox if error found,
     False if no error found
    """
    lasterr = q.lastError()
    if lasterr.isValid():
        msg = "An error occurred while {}:".format(task)
        log.error(msg)
        log.error('FAILED QUERY: "{}"'.format(q.lastQuery()))
        return msg + "\n\n{}".format(lasterr.text())
    else:
        return False