Converted sql_queries into a lazily evaluated list.

Fixed #23364. Thanks Markush2010 for the report.
Fixed a PEP 8 error.