Update sql_writer.py

almost final version of writing the full query to the file.