File indexing completed on 2026-04-10 08:39:06
0001 class SQLQueryManager:
0002 def __init__(self, sql_query):
0003 self.sql_query = sql_query
0004
0005 def format_query(self):
0006 """Format the SQL query by removing line breaks and redundant spaces."""
0007
0008 formatted_query = self.sql_query.replace('\n', ' ')
0009
0010 formatted_query = ' '.join(formatted_query.split())
0011 return formatted_query
0012
0013 def set_query(self, sql_query):
0014 """Set a new SQL query."""
0015 self.sql_query = sql_query
0016
0017 def get_query(self):
0018 """Get the current SQL query."""
0019 return self.sql_query
0020
0021 def log_query(self):
0022 """Log the formatted SQL query."""
0023 formatted_query = self.format_query()
0024 print(f"SQL Query: {formatted_query}")
0025
0026 def append(self, sql_text):
0027 """Append more text to the existing SQL query."""
0028 self.sql_query += ' ' + sql_text
0029
0030 def __str__(self):
0031 """Custom string representation of the SQLQueryManager instance."""
0032 return self.format_query()
0033
0034
0035
0036 if __name__ == "__main__":
0037
0038 sql_manager = SQLQueryManager("""
0039 SELECT *
0040 FROM your_table
0041 WHERE condition = 'something'
0042 ORDER BY column_name
0043 """)
0044
0045
0046 print(sql_manager)
0047
0048
0049 new_query = """
0050 SELECT id, name
0051 FROM another_table
0052 WHERE condition = 'another condition'
0053 """
0054 sql_manager.set_query(new_query)
0055 sql_manager.append("""
0056 AND condition2 = 'more conditions'
0057 """)
0058
0059
0060 print(sql_manager)