|
| 1 | +# Project |
| 2 | + |
| 3 | +.. image:: https://img.shields.io/pypi/v/django-mssql-backend.svg |
| 4 | + :target: https://pypi.python.org/pypi/django-mssql-backend |
| 5 | + |
| 6 | +Welcome to the MSSQL-Django 3rd party backend project! |
| 7 | + |
| 8 | +*django-mssql-backend* is a fork of |
| 9 | +`django-pyodbc-azure <https://pypi.org/project/django-pyodbc-azure/>` |
| 10 | + |
| 11 | +This project provides an enterprise database connectivity option for the Django Web Framework, with support for Microsoft SQL Server and Azure SQL Database. |
| 12 | + |
| 13 | +We hope you enjoy using the MSSQL-Django 3rd party backend. |
| 14 | + |
| 15 | +## Features |
| 16 | + |
| 17 | +- Supports Django 2.2, 3.0 |
| 18 | +- Supports Microsoft SQL Server 2008/2008R2, 2012, 2014, 2016, 2017, 2019 |
| 19 | +- Passes most of the tests of the Django test suite |
| 20 | +- Compatible with |
| 21 | + `Micosoft ODBC Driver for SQL Server <https://docs.microsoft.com/en-us/sql/connect/odbc/microsoft-odbc-driver-for-sql-server>`__, |
| 22 | + `SQL Server Native Client <https://msdn.microsoft.com/en-us/library/ms131321(v=sql.120).aspx>`__, |
| 23 | + and `FreeTDS <http://www.freetds.org/>`__ ODBC drivers |
| 24 | + |
| 25 | +## Dependencies |
| 26 | + |
| 27 | +- Django 2.2 or newer |
| 28 | +- pyodbc 3.0 or newer |
| 29 | + |
| 30 | +## Installation |
| 31 | + |
| 32 | +1. Install pyodbc and Django |
| 33 | + |
| 34 | +2. Install django-mssql-backend :: |
| 35 | + |
| 36 | + pip install django-mssql-backend |
| 37 | + |
| 38 | +3. Now you can point the ``ENGINE`` setting in the settings file used by |
| 39 | + your Django application or project to the ``'sql_server.pyodbc'`` |
| 40 | + module path :: |
| 41 | + |
| 42 | + 'ENGINE': 'sql_server.pyodbc' |
| 43 | + |
| 44 | +## Regex Support |
| 45 | + |
| 46 | +django-mssql-backend supports regex using a CLR .dll file. To install it, run :: |
| 47 | + |
| 48 | + python manage.py install_regex_clr {database_name} |
| 49 | + |
| 50 | +## Configuration |
| 51 | + |
| 52 | +### Standard Django settings |
| 53 | + |
| 54 | +The following entries in a database-level settings dictionary |
| 55 | +in DATABASES control the behavior of the backend: |
| 56 | + |
| 57 | +- ENGINE |
| 58 | + |
| 59 | + String. It must be ``"sql_server.pyodbc"``. |
| 60 | + |
| 61 | +- NAME |
| 62 | + |
| 63 | + String. Database name. Required. |
| 64 | + |
| 65 | +- HOST |
| 66 | + |
| 67 | + String. SQL Server instance in ``"server\instance"`` format. |
| 68 | + |
| 69 | +- PORT |
| 70 | + |
| 71 | + String. Server instance port. |
| 72 | + An empty string means the default port. |
| 73 | + |
| 74 | +- USER |
| 75 | + |
| 76 | + String. Database user name in ``"user"`` format. |
| 77 | + If not given then MS Integrated Security will be used. |
| 78 | + |
| 79 | +- PASSWORD |
| 80 | + |
| 81 | + String. Database user password. |
| 82 | + |
| 83 | +- AUTOCOMMIT |
| 84 | + |
| 85 | + Boolean. Set this to False if you want to disable |
| 86 | + Django's transaction management and implement your own. |
| 87 | + |
| 88 | +and the following entries are also available in the TEST dictionary |
| 89 | +for any given database-level settings dictionary: |
| 90 | + |
| 91 | +- NAME |
| 92 | + |
| 93 | + String. The name of database to use when running the test suite. |
| 94 | + If the default value (``None``) is used, the test database will use |
| 95 | + the name "test\_" + ``NAME``. |
| 96 | + |
| 97 | +- COLLATION |
| 98 | + |
| 99 | + String. The collation order to use when creating the test database. |
| 100 | + If the default value (``None``) is used, the test database is assigned |
| 101 | + the default collation of the instance of SQL Server. |
| 102 | + |
| 103 | +- DEPENDENCIES |
| 104 | + |
| 105 | + String. The creation-order dependencies of the database. |
| 106 | + See the official Django documentation for more details. |
| 107 | + |
| 108 | +- MIRROR |
| 109 | + |
| 110 | + String. The alias of the database that this database should |
| 111 | + mirror during testing. Default value is ``None``. |
| 112 | + See the official Django documentation for more details. |
| 113 | + |
| 114 | +### OPTIONS |
| 115 | + |
| 116 | +Dictionary. Current available keys are: |
| 117 | + |
| 118 | +- driver |
| 119 | + |
| 120 | + String. ODBC Driver to use (``"ODBC Driver 13 for SQL Server"``, |
| 121 | + ``"SQL Server Native Client 11.0"``, ``"FreeTDS"`` etc). |
| 122 | + Default is ``"ODBC Driver 13 for SQL Server"``. |
| 123 | + |
| 124 | +- isolation_level |
| 125 | + |
| 126 | + String. Sets `transaction isolation level |
| 127 | + <https://docs.microsoft.com/en-us/sql/t-sql/statements/set-transaction-isolation-level-transact-sql>`__ |
| 128 | + for each database session. Valid values for this entry are |
| 129 | + ``READ UNCOMMITTED``, ``READ COMMITTED``, ``REPEATABLE READ``, |
| 130 | + ``SNAPSHOT``, and ``SERIALIZABLE``. Default is ``None`` which means |
| 131 | + no isolation levei is set to a database session and SQL Server default |
| 132 | + will be used. |
| 133 | + |
| 134 | +- dsn |
| 135 | + |
| 136 | + String. A named DSN can be used instead of ``HOST``. |
| 137 | + |
| 138 | +- host_is_server |
| 139 | + |
| 140 | + Boolean. Only relevant if using the FreeTDS ODBC driver under |
| 141 | + Unix/Linux. |
| 142 | + |
| 143 | + By default, when using the FreeTDS ODBC driver the value specified in |
| 144 | + the ``HOST`` setting is used in a ``SERVERNAME`` ODBC connection |
| 145 | + string component instead of being used in a ``SERVER`` component; |
| 146 | + this means that this value should be the name of a *dataserver* |
| 147 | + definition present in the ``freetds.conf`` FreeTDS configuration file |
| 148 | + instead of a hostname or an IP address. |
| 149 | + |
| 150 | + But if this option is present and it's value is ``True``, this |
| 151 | + special behavior is turned off. |
| 152 | + |
| 153 | + See http://www.freetds.org/userguide/dsnless.htm for more information. |
| 154 | + |
| 155 | +- unicode_results |
| 156 | + |
| 157 | + Boolean. If it is set to ``True``, pyodbc's *unicode_results* feature |
| 158 | + is activated and strings returned from pyodbc are always Unicode. |
| 159 | + Default value is ``False``. |
| 160 | + |
| 161 | +- extra_params |
| 162 | + |
| 163 | + String. Additional parameters for the ODBC connection. The format is |
| 164 | + ``"param=value;param=value"``. |
| 165 | + |
| 166 | +- collation |
| 167 | + |
| 168 | + String. Name of the collation to use when performing text field |
| 169 | + lookups against the database. Default is ``None``; this means no |
| 170 | + collation specifier is added to your lookup SQL (the default |
| 171 | + collation of your database will be used). For Chinese language you |
| 172 | + can set it to ``"Chinese_PRC_CI_AS"``. |
| 173 | + |
| 174 | +- connection_timeout |
| 175 | + |
| 176 | + Integer. Sets the timeout in seconds for the database connection process. |
| 177 | + Default value is ``0`` which disables the timeout. |
| 178 | + |
| 179 | +- connection_retries |
| 180 | + |
| 181 | + Integer. Sets the times to retry the database connection process. |
| 182 | + Default value is ``5``. |
| 183 | + |
| 184 | +- connection_retry_backoff_time |
| 185 | + |
| 186 | + Integer. Sets the back off time in seconds for reries of |
| 187 | + the database connection process. Default value is ``5``. |
| 188 | + |
| 189 | +- query_timeout |
| 190 | + |
| 191 | + Integer. Sets the timeout in seconds for the database query. |
| 192 | + Default value is ``0`` which disables the timeout. |
| 193 | + |
| 194 | +### Backend-specific settings |
| 195 | +~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 196 | + |
| 197 | +The following project-level settings also control the behavior of the backend: |
| 198 | + |
| 199 | +- DATABASE_CONNECTION_POOLING |
| 200 | + |
| 201 | + Boolean. If it is set to ``False``, pyodbc's connection pooling feature |
| 202 | + won't be activated. |
| 203 | + |
| 204 | +### Example |
| 205 | + |
| 206 | +Here is an example of the database settings: |
| 207 | + |
| 208 | +:: |
| 209 | + |
| 210 | + DATABASES = { |
| 211 | + 'default': { |
| 212 | + 'ENGINE': 'sql_server.pyodbc', |
| 213 | + 'NAME': 'mydb', |
| 214 | + 'USER': 'user@myserver', |
| 215 | + 'PASSWORD': 'password', |
| 216 | + 'HOST': 'myserver.database.windows.net', |
| 217 | + 'PORT': '', |
| 218 | + |
| 219 | + 'OPTIONS': { |
| 220 | + 'driver': 'ODBC Driver 13 for SQL Server', |
| 221 | + }, |
| 222 | + }, |
| 223 | + } |
| 224 | + |
| 225 | + # set this to False if you want to turn off pyodbc's connection pooling |
| 226 | + DATABASE_CONNECTION_POOLING = False |
| 227 | + |
| 228 | +## Limitations |
| 229 | + |
| 230 | +The following features are currently not supported: |
| 231 | + |
| 232 | +- Altering a model field from or to AutoField at migration |
| 233 | + |
| 234 | +## Trademarks |
| 235 | + |
| 236 | +This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft |
| 237 | +trademarks or logos is subject to and must follow |
| 238 | +[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general). |
| 239 | +Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. |
| 240 | +Any use of third-party trademarks or logos are subject to those third-party's policies. |
0 commit comments