Skip to content

Commit f814fd9

Browse files
committed
Merge pull request pymssql#404 from pymssql/no-default-tds-version-value
Stop using 7.1 as default value for the TDS protocol version used in …
2 parents a0977c0 + d482e40 commit f814fd9

7 files changed

Lines changed: 62 additions & 32 deletions

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ install:
2020
script:
2121
- . dev/travis_env.sh
2222
- echo "\$PYMSSQL_TEST_DATABASE = \"$PYMSSQL_TEST_DATABASE\""
23+
- export TDSVER=7.1
2324
- py.test -v
2425
- cd docs && test -z "$(make SPHINXOPTS='-q' html 2>&1 | egrep -w 'SEVERE:|ERROR:')"
2526
- cd ..

ChangeLog

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,21 @@ Version 2.2.0 - To be released
77
General
88
-------
99

10+
- Stop using 7.1 as default value for the TDS protocol version used in connections.
11+
12+
This is a backward incompatible change and affects connections using both
13+
`pymssql` and `_mssql`.
14+
15+
Now you need to specify a TDS protocol version explicitly by using any of
16+
the supported mechanisms (in descending order of precedence):
17+
18+
* Using the ``tds_version`` paramenter of ``pymssql.connect()`` and
19+
``_mssql.connect()``
20+
* A ``TDSVER`` enviromnent variable (see FreeTDS documentation)
21+
* A ``freetds.conf`` file (see FreeTDS documentation)
22+
1023
- Drop support for versions of FreeTDS older than 0.91.
11-
- Add support for reporting TDS version 7.3 is i use via the ``tds_version``
24+
- Add support for reporting TDS version 7.3 is in use via the ``tds_version``
1225
property of a ``_mssql``-level connection.
1326

1427
Features

docs/ref/_mssql.rst

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Functions
7171

7272
:param str port: the TCP port to use to connect to the server
7373

74-
:param str tds_version: TDS protocol version to ask for. Default value: '7.1'
74+
:param str tds_version: TDS protocol version to ask for. Default value: ``None``
7575

7676
:param conn_properties: SQL queries to send to the server upon connection
7777
establishment. Can be a string or another kind
@@ -110,21 +110,29 @@ Functions
110110
.. versionadded:: 2.1.1
111111
The ability to connect to Azure.
112112

113-
.. warning::
114-
The *tds_version* parameter, added in version 2.0.0, has a default value
115-
of '7.1'.
116-
117-
This will change with pymssql 2.2.0 when
113+
.. versionchanged:: 2.2.0
114+
The default value of the *tds_version* parameter was changed to ``None``.
115+
Between versions 2.0.0 and 2.1.2 its default value was ``'7.1'``.
118116

119-
* The default value will be changed to None
120-
* The version of the TDS protocol to use by default won't be 7.1 anymore
121-
* You won't able to rely on such default value anymore and will need to
122-
either
123-
124-
* Specify its value explicitly or
125-
* Configure it using facilities provided by FreeTDS (see `here
126-
<http://www.freetds.org/userguide/freetdsconf.htm#TAB.FREETDS.CONF>`_
127-
`and here <http://www.freetds.org/userguide/envvar.htm>`_)
117+
.. warning::
118+
The *tds_version* parameter has a default value of ``None``. This means two
119+
things:
120+
121+
#. You can't rely anymore in the old ``'7.1'`` default value and
122+
#. Now you'll need to either
123+
124+
* Specify its value explicitly by passing a value for this parameter or
125+
* Configure it using facilities provided by FreeTDS (see `here
126+
<http://www.freetds.org/userguide/freetdsconf.htm#TAB.FREETDS.CONF>`_
127+
and `here <http://www.freetds.org/userguide/envvar.htm>`_)
128+
129+
This might look cumbersome but at the same time means you can now fully
130+
configure the characteristics of a connection to SQL Server when using
131+
pymssql/_mssql without using a stanza for the server in the
132+
``freetds.conf`` file or even with no ``freetds.conf`` at all. Starting
133+
with pymssql version 2.0.0 and up to version 2.1.2 it was already possible
134+
to set the TDS protocol version to ask for when connecting to the server
135+
but version 7.1 was used if not specified.
128136

129137
``MSSQLConnection`` object properties
130138
-------------------------------------

docs/ref/pymssql.rst

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Functions
2929
.. function:: connect(server='.', user='', password='', database='', \
3030
timeout=0, login_timeout=60, charset='UTF-8', \
3131
as_dict=False, host='', appname=None, port='1433',\
32-
conn_properties, autocommit=False, tds_version='7.1')
32+
conn_properties, autocommit=False, tds_version=None)
3333

3434
Constructor for creating a connection to the database. Returns a
3535
:class:`Connection` object.
@@ -92,23 +92,29 @@ Functions
9292
.. versionadded:: 2.1.2
9393
The *tds_version* parameter.
9494

95-
.. warning::
96-
The *tds_version* parameter, new in version 2.1.2, has a default value of
97-
'7.1'. This is for consistency with the default value of the equally-named
98-
parameter of the :class:`_mssql.connect() <_mssql.MSSQLConnection>`
99-
function.
95+
.. versionchanged:: 2.2.0
96+
The default value of the *tds_version* parameter was changed to ``None``.
97+
In version 2.1.2 its default value was ``'7.1'``.
10098

101-
This will change with pymssql 2.2.0 when
99+
.. warning::
100+
The *tds_version* parameter has a default value of ``None``. This means two
101+
things:
102102

103-
* The default value will be changed to None
104-
* The version of the TDS protocol to use by default won't be 7.1 anymore
105-
* You won't able to rely on such default value anymore and will need to
106-
either
103+
#. You can't rely anymore in the old ``'7.1'`` default value and
104+
#. Now you'll need to either
107105

108-
* Specify its value explicitly or
106+
* Specify its value explicitly by passing a value for this parameter or
109107
* Configure it using facilities provided by FreeTDS (see `here
110108
<http://www.freetds.org/userguide/freetdsconf.htm#TAB.FREETDS.CONF>`_
111-
`and here <http://www.freetds.org/userguide/envvar.htm>`_)
109+
and `here <http://www.freetds.org/userguide/envvar.htm>`_)
110+
111+
This might look cumbersome but at the same time means you can now fully
112+
configure the characteristics of a connection to SQL Server from Python
113+
code when using pymssql without using a stanza for the server in the
114+
``freetds.conf`` file or even with no ``freetds.conf`` at all. Up to
115+
version 2.1.1 it simply wasn't possible to control the TDS protocol
116+
version, and in version 2.1.2 it was possible to set it but version 7.1 was
117+
used if not specified.
112118

113119
.. function:: get_dbversion()
114120

src/_mssql.pyx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ cdef class MSSQLConnection:
540540
self.column_types = None
541541

542542
def __init__(self, server="localhost", user="sa", password="",
543-
charset='UTF-8', database='', appname=None, port='1433', tds_version='7.1', conn_properties=None):
543+
charset='UTF-8', database='', appname=None, port='1433', tds_version=None, conn_properties=None):
544544
log("_mssql.MSSQLConnection.__init__()")
545545

546546
cdef LOGINREC *login
@@ -574,7 +574,8 @@ cdef class MSSQLConnection:
574574
DBSETLUSER(login, user_cstr)
575575
DBSETLPWD(login, password_cstr)
576576
DBSETLAPP(login, appname_cstr)
577-
DBSETLVERSION(login, _tds_ver_str_to_constant(tds_version))
577+
if tds_version is not None:
578+
DBSETLVERSION(login, _tds_ver_str_to_constant(tds_version))
578579

579580
# add the port to the server string if it doesn't have one already and
580581
# if we are not using an instance

src/pymssql.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ cdef class Cursor:
580580

581581
def connect(server='.', user='', password='', database='', timeout=0,
582582
login_timeout=60, charset='UTF-8', as_dict=False,
583-
host='', appname=None, port='1433', conn_properties=None, autocommit=False, tds_version='7.1'):
583+
host='', appname=None, port='1433', conn_properties=None, autocommit=False, tds_version=None):
584584
"""
585585
Constructor for creating a connection to the database. Returns a
586586
Connection object.

tests/test_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def test_config_values(self):
3434
server='dontnameyourserverthis',
3535
user = 'bob',
3636
database = 'tempdb',
37+
tds_version='7.1'
3738
)
3839
assert 'user_name = bob' in config_dump
3940
assert 'database = tempdb\n' in config_dump

0 commit comments

Comments
 (0)