Skip to content

Commit 27a3a88

Browse files
committed
add support for Microsoft's new SQL Native Client drivers
1 parent 221bed4 commit 27a3a88

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

django_pyodbc/base.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,20 @@ def _cursor(self):
188188
else:
189189
driver = 'FreeTDS'
190190

191+
# Microsoft driver names assumed here are:
192+
# * SQL Server
193+
# * SQL Native Client
194+
# * SQL Server Native Client 10.0/11.0
195+
# * ODBC Driver 11 for SQL Server
196+
ms_drivers = re.compile('.*SQL (Server$|(Server )?Native Client)')
197+
191198
if 'dsn' in options:
192199
cstr_parts.append('DSN=%s' % options['dsn'])
193200
else:
194201
# Only append DRIVER if DATABASE_ODBC_DSN hasn't been set
195202
cstr_parts.append('DRIVER={%s}' % driver)
196203

197-
if os.name == 'nt' or driver == 'FreeTDS' and \
204+
if ms_drivers.match(driver) or driver == 'FreeTDS' and \
198205
options.get('host_is_server', False):
199206
if port_str:
200207
host_str += ';PORT=%s' % port_str
@@ -205,7 +212,7 @@ def _cursor(self):
205212
if user_str:
206213
cstr_parts.append('UID=%s;PWD=%s' % (user_str, passwd_str))
207214
else:
208-
if driver in ('SQL Server', 'SQL Native Client'):
215+
if ms_drivers.match(driver):
209216
cstr_parts.append('Trusted_Connection=yes')
210217
else:
211218
cstr_parts.append('Integrated Security=SSPI')

0 commit comments

Comments
 (0)