Skip to content

Commit c0d1f88

Browse files
authored
Merge pull request #51 from microsoft/dev
Merge dev to master for 1.0rc1 release
2 parents 9219ee7 + 9e934b0 commit c0d1f88

28 files changed

+610
-170
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Thumbs.db
77

88
*.egg-info
9-
9+
*.dll
1010
tests/local_settings.py
1111

1212
# Virtual Env

CONTRIBUTING.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,39 @@
22

33
## How to contribute
44

5+
### Run unit tests
6+
After changes made to the project, it's a good idea to run the unit tests before making a pull request.
7+
8+
9+
1. **Run SQL Server**
10+
Make sure you have SQL Server running in your local machine.
11+
Download and install SQL Server [here](https://www.microsoft.com/en-us/sql-server/sql-server-downloads), or you could use docker. Change `testapp/settings.py` to match your SQL Server login username and password.
12+
13+
```
14+
docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=MyPassword42' -p 1433:1433 -d mcr.microsoft.com/mssql/server:2019-latest
15+
```
16+
2. **Clone Django**
17+
In `mssql-django` folder.
18+
```
19+
# Install your local mssql-django
20+
pip install -e .
21+
22+
# The unit test suite are in `Django` folder, so we need to clone it
23+
git clone https://github.com/django/django.git --depth 1
24+
```
25+
26+
3. **Install Tox**
27+
```
28+
# we use `tox` to run tests and install dependencies
29+
pip install tox
30+
```
31+
4. **Run Tox**
32+
```
33+
# eg. run django 3.1 tests with Python 3.7
34+
tox -e py37-django31
35+
```
36+
37+
---
538
This project welcomes contributions and suggestions. Most contributions require you to agree to a
639
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
740
the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

LICENSE.txt

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
11
Project Name: mssql-django
22

3-
MIT License
3+
BSD 3-Clause License
44

5-
Copyright (c) Microsoft Corporation.
5+
Copyright (c) 2021, Microsoft Corporation
6+
2019, ES Solutions AB
7+
2018, Michiya Takahashi
8+
2008, 2009 django-pyodbc developers
9+
All rights reserved.
610

7-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
11+
Redistribution and use in source and binary forms, with or without
12+
modification, are permitted provided that the following conditions are met:
813

9-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14+
* Redistributions of source code must retain the above copyright notice, this
15+
list of conditions and the following disclaimer.
1016

11-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
17+
* Redistributions in binary form must reproduce the above copyright notice,
18+
this list of conditions and the following disclaimer in the documentation
19+
and/or other materials provided with the distribution.
20+
21+
* Neither the name of the copyright holder nor the names of its
22+
contributors may be used to endorse or promote products derived from
23+
this software without specific prior written permission.
24+
25+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
29+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ Welcome to the MSSQL-Django 3rd party backend project!
44

55
*mssql-django* is a fork of [django-mssql-backend](https://pypi.org/project/django-mssql-backend/). This project provides an enterprise database connectivity option for the Django Web Framework, with support for Microsoft SQL Server and Azure SQL Database.
66

7-
We'd like to give thanks to the community that made this project possible, with particular recognition of the contributors: OskarPersson, michiya, dlo and the original Google Code django-pyodbc team. Moving forward we encourage partipation in this project from both old and new contributors!
7+
We'd like to give thanks to the community that made this project possible, with particular recognition of the contributors: OskarPersson, michiya, dlo and the original Google Code django-pyodbc team. Moving forward we encourage partipation in this project from both old and new contributors!
88

99
We hope you enjoy using the MSSQL-Django 3rd party backend.
1010

1111
## Features
1212

13-
- Supports Django 2.2, 3.0
13+
- Supports Django 2.2, 3.0 and 3.1
1414
- Tested on Microsoft SQL Server 2016, 2017, 2019
1515
- Passes most of the tests of the Django test suite
1616
- Compatible with
@@ -20,12 +20,12 @@ We hope you enjoy using the MSSQL-Django 3rd party backend.
2020

2121
## Dependencies
2222

23-
- Django 2.2 or 3.0
23+
- Django 2.2, 3.0 or 3.1
2424
- pyodbc 3.0 or newer
2525

2626
## Installation
2727

28-
1. Install pyodbc 3.0 (or newer) and Django 2.2 (or 3.0)
28+
1. Install pyodbc 3.0 (or newer) and Django 2.2, 3.0 or 3.1
2929

3030
2. Install mssql-django:
3131

@@ -74,14 +74,18 @@ in DATABASES control the behavior of the backend:
7474
Boolean. Set this to `False` if you want to disable
7575
Django's transaction management and implement your own.
7676

77+
- Trusted_Connection
78+
79+
String. Default is `"yes"`. Can be set to `"no"` if required.
80+
7781
and the following entries are also available in the `TEST` dictionary
7882
for any given database-level settings dictionary:
7983

8084
- NAME
8185

8286
String. The name of database to use when running the test suite.
8387
If the default value (`None`) is used, the test database will use
84-
the name `"test\_" + NAME`.
88+
the name `"test_" + NAME`.
8589

8690
- COLLATION
8791

@@ -135,10 +139,12 @@ Dictionary. Current available keys are:
135139
definition present in the ``freetds.conf`` FreeTDS configuration file
136140
instead of a hostname or an IP address.
137141

138-
But if this option is present and it's value is ``True``, this
139-
special behavior is turned off.
142+
But if this option is present and its value is ``True``, this
143+
special behavior is turned off. Instead, connections to the database
144+
server will be established using ``HOST`` and ``PORT`` options, without
145+
requiring ``freetds.conf`` to be configured.
140146

141-
See http://www.freetds.org/userguide/dsnless.htm for more information.
147+
See https://www.freetds.org/userguide/dsnless.html for more information.
142148

143149
- unicode_results
144150

@@ -149,7 +155,7 @@ Dictionary. Current available keys are:
149155
- extra_params
150156

151157
String. Additional parameters for the ODBC connection. The format is
152-
``"param=value;param=value"``.
158+
``"param=value;param=value"``, [Azure AD Authentication](https://github.com/microsoft/mssql-django/wiki/Azure-AD-Authentication) can be added to this field.
153159

154160
- collation
155161

@@ -216,7 +222,9 @@ Here is an example of the database settings:
216222

217223
The following features are currently not supported:
218224
- mssql-django does not support SQL-based regex commands
219-
- Altering a model field from or to AutoField at migration
225+
- Altering a model field from or to AutoField at migration
226+
227+
Certain limitations for JSONField lookups, more details [here](https://github.com/microsoft/mssql-django/wiki/JSONField).
220228

221229
## Future Plans
222230

@@ -225,6 +233,8 @@ The following features and additions are planned:
225233

226234
## Contributing
227235

236+
More details on contributing can be found [Here](CONTRIBUTING.md).
237+
228238
This project welcomes contributions and suggestions. Most contributions require you to agree to a
229239
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
230240
the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

azure-pipelines.yml

Lines changed: 24 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -14,68 +14,28 @@ schedules:
1414
always: true
1515

1616
jobs:
17-
- job: Windows
17+
- job: Linux
1818
pool:
19-
Django-agent-pool
19+
vmImage: ubuntu-18.04
2020

2121
strategy:
2222
matrix:
23-
Python 3.8 - Django 3.1:
23+
Python 3.9 - Django 3.2:
24+
python.version: '3.9'
25+
tox.env: 'py39-django32'
26+
Python 3.8 - Django 3.2:
2427
python.version: '3.8'
25-
tox.env: 'py38-django31'
26-
Python 3.7 - Django 3.1:
28+
tox.env: 'py38-django32'
29+
Python 3.7 - Django 3.2:
2730
python.version: '3.7'
28-
tox.env: 'py37-django31'
29-
Python 3.6 - Django 3.1:
31+
tox.env: 'py37-django32'
32+
Python 3.6 - Django 3.2:
3033
python.version: '3.6'
31-
tox.env: 'py36-django31'
34+
tox.env: 'py36-django32'
3235

33-
Python 3.8 - Django 3.0:
34-
python.version: '3.8'
35-
tox.env: 'py38-django30'
36-
Python 3.7 - Django 3.0:
37-
python.version: '3.7'
38-
tox.env: 'py37-django30'
39-
Python 3.6 - Django 3.0:
40-
python.version: '3.6'
41-
tox.env: 'py36-django30'
42-
43-
Python 3.7 - Django 2.2:
44-
python.version: '3.7'
45-
tox.env: 'py37-django22'
46-
Python 3.6 - Django 2.2:
47-
python.version: '3.6'
48-
tox.env: 'py36-django22'
49-
50-
steps:
51-
- task: CredScan@2
52-
inputs:
53-
toolMajorVersion: 'V2'
54-
- task: UsePythonVersion@0
55-
inputs:
56-
versionSpec: "$(python.version)"
57-
displayName: Use Python $(python.version)
58-
59-
- script: |
60-
python -m pip install --upgrade pip wheel setuptools
61-
pip install tox
62-
git clone https://github.com/django/django.git
63-
displayName: Install requirements
64-
65-
- script: tox -e $(tox.env)
66-
displayName: Run tox
67-
68-
- task: PublishCodeCoverageResults@1
69-
inputs:
70-
codeCoverageTool: 'Cobertura'
71-
summaryFileLocation: 'C:\Windows\ServiceProfiles\NetworkService\coverage.xml'
72-
73-
- job: Linux
74-
pool:
75-
vmImage: ubuntu-18.04
76-
77-
strategy:
78-
matrix:
36+
Python 3.9 - Django 3.1:
37+
python.version: '3.9'
38+
tox.env: 'py39-django31'
7939
Python 3.8 - Django 3.1:
8040
python.version: '3.8'
8141
tox.env: 'py38-django31'
@@ -86,6 +46,9 @@ jobs:
8646
python.version: '3.6'
8747
tox.env: 'py36-django31'
8848

49+
Python 3.9 - Django 3.0:
50+
python.version: '3.9'
51+
tox.env: 'py39-django30'
8952
Python 3.8 - Django 3.0:
9053
python.version: '3.8'
9154
tox.env: 'py38-django30'
@@ -131,3 +94,10 @@ jobs:
13194
inputs:
13295
codeCoverageTool: 'Cobertura'
13396
summaryFileLocation: '/home/vsts/coverage.xml'
97+
98+
- task: PublishTestResults@2
99+
displayName: Publish test results via jUnit
100+
inputs:
101+
testResultsFormat: 'JUnit'
102+
testResultsFiles: '/home/vsts/result.xml'
103+
testRunTitle: 'junit-$(Agent.OS)-$(Agent.OSArchitecture)-$(tox.env)'

manage.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
#!/usr/bin/env python
2+
13
# Copyright (c) Microsoft Corporation.
2-
# Licensed under the MIT license.
4+
# Licensed under the BSD license.
35

4-
#!/usr/bin/env python
56
import os
67
import sys
78

mssql/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Copyright (c) Microsoft Corporation.
2-
# Licensed under the MIT license.
2+
# Licensed under the BSD license.
33

44
import mssql.functions # noqa

mssql/base.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Copyright (c) Microsoft Corporation.
2-
# Licensed under the MIT license.
2+
# Licensed under the BSD license.
33

44
"""
55
MS SQL Server database backend for Django.
@@ -75,7 +75,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
7575
'AutoField': 'int',
7676
'BigAutoField': 'bigint',
7777
'BigIntegerField': 'bigint',
78-
'BinaryField': 'varbinary(max)',
78+
'BinaryField': 'varbinary(%(max_length)s)',
7979
'BooleanField': 'bit',
8080
'CharField': 'nvarchar(%(max_length)s)',
8181
'DateField': 'date',
@@ -88,10 +88,12 @@ class DatabaseWrapper(BaseDatabaseWrapper):
8888
'IntegerField': 'int',
8989
'IPAddressField': 'nvarchar(15)',
9090
'GenericIPAddressField': 'nvarchar(39)',
91+
'JSONField': 'nvarchar(max)',
9192
'NullBooleanField': 'bit',
9293
'OneToOneField': 'int',
9394
'PositiveIntegerField': 'int',
9495
'PositiveSmallIntegerField': 'smallint',
96+
'PositiveBigIntegerField' : 'bigint',
9597
'SlugField': 'nvarchar(%(max_length)s)',
9698
'SmallAutoField': 'smallint',
9799
'SmallIntegerField': 'smallint',
@@ -105,8 +107,10 @@ class DatabaseWrapper(BaseDatabaseWrapper):
105107
'SmallAutoField': 'IDENTITY (1, 1)',
106108
}
107109
data_type_check_constraints = {
110+
'JSONField': '(ISJSON ("%(column)s") = 1)',
108111
'PositiveIntegerField': '[%(column)s] >= 0',
109112
'PositiveSmallIntegerField': '[%(column)s] >= 0',
113+
'PositiveBigIntegerField': '[%(column)s] >= 0',
110114
}
111115
operators = {
112116
# Since '=' is used not only for string comparision there is no way
@@ -249,9 +253,10 @@ def get_new_connection(self, conn_params):
249253
user = conn_params.get('USER', None)
250254
password = conn_params.get('PASSWORD', None)
251255
port = conn_params.get('PORT', None)
256+
trusted_connection = conn_params.get('Trusted_Connection', 'yes')
252257

253258
options = conn_params.get('OPTIONS', {})
254-
driver = options.get('driver', 'ODBC Driver 13 for SQL Server')
259+
driver = options.get('driver', 'ODBC Driver 17 for SQL Server')
255260
dsn = options.get('dsn', None)
256261

257262
# Microsoft driver names assumed here are:
@@ -286,10 +291,11 @@ def get_new_connection(self, conn_params):
286291

287292
if user:
288293
cstr_parts['UID'] = user
289-
cstr_parts['PWD'] = password
294+
if 'Authentication=ActiveDirectoryInteractive' not in options.get('extra_params', ''):
295+
cstr_parts['PWD'] = password
290296
else:
291297
if ms_drivers.match(driver):
292-
cstr_parts['Trusted_Connection'] = 'yes'
298+
cstr_parts['Trusted_Connection'] = trusted_connection
293299
else:
294300
cstr_parts['Integrated Security'] = 'SSPI'
295301

@@ -487,12 +493,12 @@ def check_constraints(self, table_names=None):
487493

488494
def disable_constraint_checking(self):
489495
if not self.needs_rollback:
490-
self.cursor().execute('EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT ALL"')
496+
self._execute_foreach('ALTER TABLE %s NOCHECK CONSTRAINT ALL')
491497
return not self.needs_rollback
492498

493499
def enable_constraint_checking(self):
494500
if not self.needs_rollback:
495-
self.cursor().execute('EXEC sp_msforeachtable "ALTER TABLE ? WITH CHECK CHECK CONSTRAINT ALL"')
501+
self._execute_foreach('ALTER TABLE %s WITH NOCHECK CHECK CONSTRAINT ALL')
496502

497503

498504
class CursorWrapper(object):

mssql/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Copyright (c) Microsoft Corporation.
2-
# Licensed under the MIT license.
2+
# Licensed under the BSD license.
33

44
import re
55
import subprocess

0 commit comments

Comments
 (0)