11
11
from dbt .adapters .fabric .fabric_connection_manager import (
12
12
AZURE_CREDENTIAL_SCOPE ,
13
13
bool_to_connection_string_arg ,
14
- get_pyodbc_attrs_before ,
14
+ get_pyodbc_attrs_before_accesstoken ,
15
+ get_pyodbc_attrs_before_credentials ,
15
16
)
16
17
17
18
from dbt .adapters .sqlserver import __version__
@@ -70,27 +71,6 @@ def get_sp_access_token(credentials: SQLServerCredentials) -> AccessToken:
70
71
class SQLServerConnectionManager (FabricConnectionManager ):
71
72
TYPE = "sqlserver"
72
73
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
-
94
74
@classmethod
95
75
def open (cls , connection : Connection ) -> Connection :
96
76
if connection .state == ConnectionState .OPEN :
@@ -156,7 +136,11 @@ def open(cls, connection: Connection) -> Connection:
156
136
def connect ():
157
137
logger .debug (f"Using connection string: { con_str_display } " )
158
138
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
+
160
144
handle = pyodbc .connect (
161
145
con_str_concat ,
162
146
attrs_before = attrs_before ,
@@ -174,28 +158,3 @@ def connect():
174
158
retry_limit = credentials .retries ,
175
159
retryable_exceptions = retryable_exceptions ,
176
160
)
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