You uploaded the file yourself Sergey. I downloaded the zip file from the link at the end of that post. I just modified some things in the code to adapt it to my project.
In any case, thank you very much for reviewing and finding the error, it was not easy.

Could you please try to remove the query completely, including quotes, and type it again? Will it work?

The initial problem was is that query somehow contains the UTF-8 byte order mark (3 bytes, EF BB BF), and it breaks the SQLite lexer.
After retyping the query I was able to get the report.
We can add protection against it, but it is better to understand how was this string created.

Maybe I can help you. When I load an empty query the project doesn't work immediately, in debug mode I have checked that initially the mreport variable has the pagecount value to 0 but after a few seconds it goes to pagecount 1 and then the report is generated as an empty pdf. If I load the previous query (Select * from T1) the same thing happens, until pagecount is not equal to 1 the report is not generated but it is also empty. I hope it helps you to detect the problem.

I have added Valentina.InitReports and Valentina.ShutdownReports in open and close events but I get this error message when I run the project: "An exception of class VException was not handled. The application must shut down. Exception Message: Sqlite db "reports_db.sqlite": Error : "near "﻿SELECT": syntax error". Exception Error Number: 427264"