Fix #4442 New lines are added to query every time

Remove trailing whitespaces in SQL queries.