Fix wrong queries storage with lock and temporary file reports. Thanks to Thomas Reiss for the report.