1111from dbt .adapters .fabric .fabric_connection_manager import (
1212 AZURE_CREDENTIAL_SCOPE ,
1313 bool_to_connection_string_arg ,
14- get_pyodbc_attrs_before ,
14+ get_pyodbc_attrs_before_accesstoken ,
15+ get_pyodbc_attrs_before_credentials ,
1516)
1617
1718from dbt .adapters .sqlserver import __version__
@@ -70,27 +71,6 @@ def get_sp_access_token(credentials: SQLServerCredentials) -> AccessToken:
7071class SQLServerConnectionManager (FabricConnectionManager ):
7172 TYPE = "sqlserver"
7273
73- # @contextmanager
74- # def exception_handler(self, sql: str):
75- # """
76- # Returns a context manager, that will handle exceptions raised
77- # from queries, catch, log, and raise dbt exceptions it knows how to handle.
78- # """
79- # # ## Example ##
80- # # try:
81- # # yield
82- # # except myadapter_library.DatabaseError as exc:
83- # # self.release(connection_name)
84-
85- # # logger.debug("myadapter error: {}".format(str(e)))
86- # # raise dbt.exceptions.DatabaseException(str(exc))
87- # # except Exception as exc:
88- # # logger.debug("Error running SQL: {}".format(sql))
89- # # logger.debug("Rolling back transaction.")
90- # # self.release(connection_name)
91- # # raise dbt.exceptions.RuntimeException(str(exc))
92- # pass
93-
9474 @classmethod
9575 def open (cls , connection : Connection ) -> Connection :
9676 if connection .state == ConnectionState .OPEN :
@@ -156,7 +136,11 @@ def open(cls, connection: Connection) -> Connection:
156136 def connect ():
157137 logger .debug (f"Using connection string: { con_str_display } " )
158138
159- attrs_before = get_pyodbc_attrs_before (credentials )
139+ if credentials .authentication == "ActiveDirectoryAccessToken" :
140+ attrs_before = get_pyodbc_attrs_before_accesstoken (credentials .access_token )
141+ else :
142+ attrs_before = get_pyodbc_attrs_before_credentials (credentials )
143+
160144 handle = pyodbc .connect (
161145 con_str_concat ,
162146 attrs_before = attrs_before ,
@@ -174,28 +158,3 @@ def connect():
174158 retry_limit = credentials .retries ,
175159 retryable_exceptions = retryable_exceptions ,
176160 )
177-
178- # @classmethod
179- # def get_response(cls,cursor):
180- # """
181- # Gets a cursor object and returns adapter-specific information
182- # about the last executed command generally a AdapterResponse ojbect
183- # that has items such as code, rows_affected,etc. can also just be a string ex. "OK"
184- # if your cursor does not offer rich metadata.
185- # """
186- # # ## Example ##
187- # # return cursor.status_message
188- # pass
189-
190- # def cancel(self, connection):
191- # """
192- # Gets a connection object and attempts to cancel any ongoing queries.
193- # """
194- # # ## Example ##
195- # # tid = connection.handle.transaction_id()
196- # # sql = "select cancel_transaction({})".format(tid)
197- # # logger.debug("Cancelling query "{}" ({})".format(connection_name, pid))
198- # # _, cursor = self.add_query(sql, "master")
199- # # res = cursor.fetchone()
200- # # logger.debug("Canceled query "{}": {}".format(connection_name, res))
201- # pass
0 commit comments