def test_strip_comments_from_sql() -> None: """ Test that comments are stripped out correctly. """ assert (strip_comments_from_sql("SELECT col1, col2 FROM table1") == "SELECT col1, col2 FROM table1") assert (strip_comments_from_sql("SELECT col1, col2 FROM table1\n-- comment" ) == "SELECT col1, col2 FROM table1\n") assert ( strip_comments_from_sql("SELECT '--abc' as abc, col2 FROM table1\n") == "SELECT '--abc' as abc, col2 FROM table1")
def test_strip_comments_from_sql(self): """Test that we are able to strip comments out of SQL stmts""" assert ( strip_comments_from_sql("SELECT col1, col2 FROM table1") == "SELECT col1, col2 FROM table1" ) assert ( strip_comments_from_sql("SELECT col1, col2 FROM table1\n-- comment") == "SELECT col1, col2 FROM table1\n" ) assert ( strip_comments_from_sql("SELECT '--abc' as abc, col2 FROM table1\n") == "SELECT '--abc' as abc, col2 FROM table1" )
def execute(cls, cursor: Any, query: str, **kwargs: Any) -> None: """ Execute a SQL query :param cursor: Cursor instance :param query: Query to execute :param kwargs: kwargs to be passed to cursor.execute() :return: """ if not cls.allows_sql_comments: query = sql_parse.strip_comments_from_sql(query) if cls.arraysize: cursor.arraysize = cls.arraysize try: cursor.execute(query) except Exception as ex: raise cls.get_dbapi_mapped_exception(ex)