Python SQL Query Generator