From 5858095535985a48f208303064a9456727a59914 Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Thu, 2 Mar 2023 13:05:07 -0500 Subject: [PATCH] add_select_query --- core/dbt/adapters/base/impl.py | 8 ++------ core/dbt/adapters/sql/connections.py | 7 ++++--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/core/dbt/adapters/base/impl.py b/core/dbt/adapters/base/impl.py index a36ecdbc927..97e8ac13369 100644 --- a/core/dbt/adapters/base/impl.py +++ b/core/dbt/adapters/base/impl.py @@ -269,12 +269,8 @@ def execute( @available.parse(lambda *a, **k: []) def get_column_schema_from_query(self, sql: str) -> List[BaseColumn]: - """Get a list of the column names and data types from the given sql. - - :param str sql: The sql to execute. - :return: List[Column] - """ - _, cursor = self.connections.add_query(sql, add_comment=True) + """Get a list of the Columns with names and data types from the given sql.""" + _, cursor = self.connections.add_select_query(sql) columns = [ self.Column.create( column_name, self.connections.data_type_code_to_name(column_type_code) diff --git a/core/dbt/adapters/sql/connections.py b/core/dbt/adapters/sql/connections.py index deb9e1d7b98..88e4a30d0b6 100644 --- a/core/dbt/adapters/sql/connections.py +++ b/core/dbt/adapters/sql/connections.py @@ -51,10 +51,7 @@ def add_query( auto_begin: bool = True, bindings: Optional[Any] = None, abridge_sql_log: bool = False, - add_comment: bool = False, ) -> Tuple[Connection, Any]: - if add_comment: - sql = self._add_query_comment(sql) connection = self.get_thread_connection() if auto_begin and connection.transaction_open is False: @@ -158,6 +155,10 @@ def add_begin_query(self): def add_commit_query(self): return self.add_query("COMMIT", auto_begin=False) + def add_select_query(self, sql: str) -> Tuple[Connection, Any]: + sql = self._add_query_comment(sql) + return self.add_query(sql, auto_begin=False) + def begin(self): connection = self.get_thread_connection() if connection.transaction_open is True: