Package: zilian-mssql-django
SQL Server backend for DjangoWelcome to the Zilian-MSSQL-Django 3rd party backend project!zilian-mssql-djangois a fork ofmssql-django. This project provides an enterprise database connectivity option for the Django Web Framework, with support for Microsoft SQL Server and Azure SQL Database.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!We hope you enjoy using the Zilian-MSSQL-Django 3rd party backend.FeaturesSupports Django 3.2 and 4.0Tested on Microsoft SQL Server 2016, 2017, 2019Passes most of the tests of the Django test suiteCompatible withMicosoft ODBC Driver for SQL Server,SQL Server Native Client,
andFreeTDSODBC driversSupports AzureSQL serveless db reconnectionDependenciespyodbc 3.0 or newerInstallationInstall pyodbc 3.0 (or newer) and DjangoInstall zilian-mssql-django:pip install zilian-mssql-djangoSet theENGINEsetting in thesettings.pyfile used by
your Django application or project to'mssql':'ENGINE': 'mssql'ConfigurationStandard Django settingsThe following entries in a database-level settings dictionary
in DATABASES control the behavior of the backend:ENGINEString. It must be"mssql".NAMEString. Database name. Required.HOSTString. SQL Server instance in"server\instance"format.PORTString. Server instance port.
An empty string means the default port.USERString. Database user name in"user"format.
If not given then MS Integrated Security will be used.PASSWORDString. Database user password.TOKENString. Access token fetched as a user or service principal which
has access to the database. E.g. when usingazure.identity, the
result ofDefaultAzureCredential().get_token('https://database.windows.net/.default')can be passed.AUTOCOMMITBoolean. Set this toFalseif you want to disable
Django's transaction management and implement your own.Trusted_ConnectionString. Default is"yes". Can be set to"no"if required.and the following entries are also available in theTESTdictionary
for any given database-level settings dictionary:NAMEString. The name of database to use when running the test suite.
If the default value (None) is used, the test database will use
the name"test_" + NAME.COLLATIONString. The collation order to use when creating the test database.
If the default value (None) is used, the test database is assigned
the default collation of the instance of SQL Server.DEPENDENCIESString. The creation-order dependencies of the database.
See the official Django documentation for more details.MIRRORString. The alias of the database that this database should
mirror during testing. Default value isNone.
See the official Django documentation for more details.OPTIONSDictionary. Current available keys are:driverString. ODBC Driver to use ("ODBC Driver 17 for SQL Server","SQL Server Native Client 11.0","FreeTDS"etc).
Default is"ODBC Driver 17 for SQL Server".isolation_levelString. Setstransaction isolation levelfor each database session. Valid values for this entry areREAD UNCOMMITTED,READ COMMITTED,REPEATABLE READ,SNAPSHOT, andSERIALIZABLE. Default isNonewhich means
no isolation levei is set to a database session and SQL Server default
will be used.dsnString. A named DSN can be used instead ofHOST.host_is_serverBoolean. Only relevant if using the FreeTDS ODBC driver under
Unix/Linux.By default, when using the FreeTDS ODBC driver the value specified in
theHOSTsetting is used in aSERVERNAMEODBC connection
string component instead of being used in aSERVERcomponent;
this means that this value should be the name of adataserverdefinition present in thefreetds.confFreeTDS configuration file
instead of a hostname or an IP address.But if this option is present and its value isTrue, this
special behavior is turned off. Instead, connections to the database
server will be established usingHOSTandPORToptions, without
requiringfreetds.confto be configured.Seehttps://www.freetds.org/userguide/dsnless.htmlfor more information.unicode_resultsBoolean. If it is set toTrue, pyodbc'sunicode_resultsfeature
is activated and strings returned from pyodbc are always Unicode.
Default value isFalse.extra_paramsString. Additional parameters for the ODBC connection. The format is"param=value;param=value",Azure AD Authentication(Service Principal, Interactive, Msi) can be added to this field.collationString. Name of the collation to use when performing text field
lookups against the database. Default isNone; this means no
collation specifier is added to your lookup SQL (the default
collation of your database will be used). For Chinese language you
can set it to"Chinese_PRC_CI_AS".connection_timeoutInteger. Sets the timeout in seconds for the database connection process.
Default value is0which disables the timeout.connection_retriesInteger. Sets the times to retry the database connection process.
Default value is5.connection_retry_backoff_timeInteger. Sets the back off time in seconds for reries of
the database connection process. Default value is5.query_timeoutInteger. Sets the timeout in seconds for the database query.
Default value is0which disables the timeout.setencodingandsetdecoding# Example"OPTIONS":{"setdecoding":[{"sqltype":pyodbc.SQL_CHAR,"encoding":'utf-8'},{"sqltype":pyodbc.SQL_WCHAR,"encoding":'utf-8'}],"setencoding":[{"encoding":"utf-8"}],...},Backend-specific settingsThe following project-level settings also control the behavior of the backend:DATABASE_CONNECTION_POOLINGBoolean. If it is set toFalse, pyodbc's connection pooling feature
won't be activated.ExampleHere is an example of the database settings:DATABASES={'default':{'ENGINE':'mssql','NAME':'mydb','USER':'user@myserver','PASSWORD':'password','HOST':'myserver.database.windows.net','PORT':'','OPTIONS':{'driver':'ODBC Driver 17 for SQL Server',},},}# set this to False if you want to turn off pyodbc's connection poolingDATABASE_CONNECTION_POOLING=FalseLimitationsThe following features are currently not fully supported:Altering a model field from or to AutoField at migrationDjango annotate functions have floating point arithmetic problems in some casesAnnotate function with existsExists function in order_byRighthand power and arithmetic with datatimesTimezones, timedeltas not fully supportedRename field/model with foreign key constraintDatabase level constraintsMath degrees power or radiansBit-shift operatorsFiltered indexDate extract functionHashing functionsJSONField lookups have limitations, more detailshere.