def __init__(self, *args, **kwargs): self.use_transactions = kwargs.pop('use_transactions', None) super(DatabaseWrapper, self).__init__(*args, **kwargs) try: self.command_timeout = int( self.settings_dict.get('COMMAND_TIMEOUT', 30)) except ValueError: self.command_timeout = 30 options = self.settings_dict.get('OPTIONS', {}) try: self.cast_avg_to_float = not bool( options.get('disable_avg_cast', False)) except ValueError: self.cast_avg_to_float = False self.features = DatabaseFeatures(self) self.ops = DatabaseOperations(self) self.client = BaseDatabaseClient(self) self.creation = DatabaseCreation(self) self.introspection = DatabaseIntrospection(self) self.validation = BaseDatabaseValidation(self)
def __init__(self, *args, **kwargs): self.use_transactions = kwargs.pop('use_transactions', None) super(DatabaseWrapper, self).__init__(*args, **kwargs) try: self.command_timeout = int(self.settings_dict.get('COMMAND_TIMEOUT', 30)) except ValueError: self.command_timeout = 30 options = self.settings_dict.get('OPTIONS', {}) try: self.cast_avg_to_float = not bool(options.get('disable_avg_cast', False)) except ValueError: self.cast_avg_to_float = False self.features = DatabaseFeatures(self) self.ops = DatabaseOperations(self) self.client = BaseDatabaseClient(self) self.creation = DatabaseCreation(self) self.introspection = DatabaseIntrospection(self) self.validation = BaseDatabaseValidation(self)
class DatabaseWrapper(BaseDatabaseWrapper): vendor = 'microsoft' jdbc_driver_class_name = 'net.sourceforge.jtds.jdbc.Driver' jdbc_connection_url_pattern = 'jdbc:jtds:sqlserver://%(HOST)s:%(PORT)s/%(NAME)s' jdbc_default_host = 'localhost' jdbc_default_port = 1433 jdbc_default_name = 'master' # This dictionary maps Field objects to their associated Server Server column # types, as strings. Column-type strings can contain format strings; they'll # be interpolated against the values of Field.__dict__. data_types = { 'AutoField': 'int IDENTITY (1, 1)', 'BigAutoField': 'bigint IDENTITY (1, 1)', 'BigIntegerField': 'bigint', 'BinaryField': 'varbinary(max)', 'BooleanField': 'bit', 'CharField': 'nvarchar(%(max_length)s)', 'CommaSeparatedIntegerField': 'nvarchar(%(max_length)s)', 'DateField': 'date', 'DateTimeField': 'datetime2', 'DateTimeOffsetField': 'datetimeoffset', 'DecimalField': 'decimal(%(max_digits)s, %(decimal_places)s)', 'FileField': 'nvarchar(%(max_length)s)', 'FilePathField': 'nvarchar(%(max_length)s)', 'FloatField': 'double precision', 'GenericIPAddressField': 'nvarchar(39)', 'IntegerField': 'int', 'IPAddressField': 'nvarchar(15)', 'NullBooleanField': 'bit', 'OneToOneField': 'int', 'PositiveIntegerField': 'int', 'PositiveSmallIntegerField': 'smallint', 'SlugField': 'nvarchar(%(max_length)s)', 'SmallIntegerField': 'smallint', 'TextField': 'nvarchar(max)', 'TimeField': 'time', } # Starting with Django 1.7, check constraints are no longer included in with # the data_types value. data_type_check_constraints = { 'PositiveIntegerField': '%(qn_column)s >= 0', 'PositiveSmallIntegerField': '%(qn_column)s >= 0', } operators = { "exact": "= %s", "iexact": "LIKE %s ESCAPE '\\'", "contains": "LIKE %s ESCAPE '\\'", "icontains": "LIKE %s ESCAPE '\\'", "gt": "> %s", "gte": ">= %s", "lt": "< %s", "lte": "<= %s", "startswith": "LIKE %s ESCAPE '\\'", "endswith": "LIKE %s ESCAPE '\\'", "istartswith": "LIKE %s ESCAPE '\\'", "iendswith": "LIKE %s ESCAPE '\\'", } def __init__(self, *args, **kwargs): self.use_transactions = kwargs.pop('use_transactions', None) super(DatabaseWrapper, self).__init__(*args, **kwargs) try: self.command_timeout = int(self.settings_dict.get('COMMAND_TIMEOUT', 30)) except ValueError: self.command_timeout = 30 options = self.settings_dict.get('OPTIONS', {}) try: self.cast_avg_to_float = not bool(options.get('disable_avg_cast', False)) except ValueError: self.cast_avg_to_float = False self.features = DatabaseFeatures(self) self.ops = DatabaseOperations(self) self.client = BaseDatabaseClient(self) self.creation = DatabaseCreation(self) self.introspection = DatabaseIntrospection(self) self.validation = BaseDatabaseValidation(self) def init_connection_state(self): pass def disable_constraint_checking(self): """ Turn off constraint checking for every table """ cursor = self.cursor() cursor.execute('EXEC sp_MSforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"') return True def enable_constraint_checking(self): """ Turn on constraint checking for every table """ cursor = self.cursor() cursor.execute('EXEC sp_MSforeachtable "ALTER TABLE ? WITH NOCHECK CHECK CONSTRAINT all"') def check_constraints(self, table_names=None): """ Check the table constraints. """ cursor = self.cursor() if not table_names: cursor.execute('DBCC CHECKCONSTRAINTS WITH ALL_CONSTRAINTS') if cursor.description: raise DjangoIntegrityError(cursor.fetchall()) else: qn = self.ops.quote_name for name in table_names: cursor.execute('DBCC CHECKCONSTRAINTS({0}) WITH ALL_CONSTRAINTS'.format( qn(name) )) if cursor.description: raise DjangoIntegrityError(cursor.fetchall()) # MS SQL Server doesn't support explicit savepoint commits; savepoints are # implicitly committed with the transaction. # Ignore them. def _savepoint_commit(self, sid): queries_log = self.queries if queries_log: queries_log.append({ 'sql': '-- RELEASE SAVEPOINT %s -- (because assertNumQueries)' % self.ops.quote_name(sid), 'time': '0.000', }) def is_usable(self): try: self.connection.cursor().execute("SELECT 1") except self.Error: return False else: return True def schema_editor(self, *args, **kwargs): return DatabaseSchemaEditor(self, *args, **kwargs)
class DatabaseWrapper(BaseDatabaseWrapper): vendor = 'microsoft' jdbc_driver_class_name = 'net.sourceforge.jtds.jdbc.Driver' jdbc_connection_url_pattern = 'jdbc:jtds:sqlserver://%(HOST)s:%(PORT)s/%(NAME)s' jdbc_default_host = 'localhost' jdbc_default_port = 1433 jdbc_default_name = 'master' operators = { "exact": "= %s", "iexact": "LIKE %s ESCAPE '\\'", "contains": "LIKE %s ESCAPE '\\'", "icontains": "LIKE %s ESCAPE '\\'", "gt": "> %s", "gte": ">= %s", "lt": "< %s", "lte": "<= %s", "startswith": "LIKE %s ESCAPE '\\'", "endswith": "LIKE %s ESCAPE '\\'", "istartswith": "LIKE %s ESCAPE '\\'", "iendswith": "LIKE %s ESCAPE '\\'", } def __init__(self, *args, **kwargs): self.use_transactions = kwargs.pop('use_transactions', None) super(DatabaseWrapper, self).__init__(*args, **kwargs) try: self.command_timeout = int(self.settings_dict.get('COMMAND_TIMEOUT', 30)) except ValueError: self.command_timeout = 30 options = self.settings_dict.get('OPTIONS', {}) try: self.cast_avg_to_float = not bool(options.get('disable_avg_cast', False)) except ValueError: self.cast_avg_to_float = False self.features = DatabaseFeatures(self) self.ops = DatabaseOperations(self) self.client = BaseDatabaseClient(self) self.creation = DatabaseCreation(self) self.introspection = DatabaseIntrospection(self) self.validation = BaseDatabaseValidation(self) def init_connection_state(self): pass def disable_constraint_checking(self): """ Turn off constraint checking for every table """ cursor = self.cursor() cursor.execute('EXEC sp_MSforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"') return True def enable_constraint_checking(self): """ Turn on constraint checking for every table """ cursor = self.cursor() cursor.execute('EXEC sp_MSforeachtable "ALTER TABLE ? WITH NOCHECK CHECK CONSTRAINT all"') def check_constraints(self, table_names=None): """ Check the table constraints. """ cursor = self.cursor() if not table_names: cursor.execute('DBCC CHECKCONSTRAINTS WITH ALL_CONSTRAINTS') if cursor.description: raise DjangoIntegrityError(cursor.fetchall()) else: qn = self.ops.quote_name for name in table_names: cursor.execute('DBCC CHECKCONSTRAINTS({0}) WITH ALL_CONSTRAINTS'.format( qn(name) )) if cursor.description: raise DjangoIntegrityError(cursor.fetchall()) # MS SQL Server doesn't support explicit savepoint commits; savepoints are # implicitly committed with the transaction. # Ignore them. def _savepoint_commit(self, sid): queries_log = self.queries if queries_log: queries_log.append({ 'sql': '-- RELEASE SAVEPOINT %s -- (because assertNumQueries)' % self.ops.quote_name(sid), 'time': '0.000', }) def is_usable(self): try: self.connection.cursor().execute("SELECT 1") except self.Error: return False else: return True def schema_editor(self, *args, **kwargs): return DatabaseSchemaEditor(self, *args, **kwargs)
class DatabaseWrapper(BaseDatabaseWrapper): vendor = 'microsoft' jdbc_driver_class_name = 'net.sourceforge.jtds.jdbc.Driver' jdbc_connection_url_pattern = 'jdbc:jtds:sqlserver://%(HOST)s:%(PORT)s/%(NAME)s' jdbc_default_host = 'localhost' jdbc_default_port = 1433 jdbc_default_name = 'master' # This dictionary maps Field objects to their associated Server Server column # types, as strings. Column-type strings can contain format strings; they'll # be interpolated against the values of Field.__dict__. data_types = { 'AutoField': 'int IDENTITY (1, 1)', 'BigAutoField': 'bigint IDENTITY (1, 1)', 'BigIntegerField': 'bigint', 'BinaryField': 'varbinary(max)', 'BooleanField': 'bit', 'CharField': 'nvarchar(%(max_length)s)', 'CommaSeparatedIntegerField': 'nvarchar(%(max_length)s)', 'DateField': 'date', 'DateTimeField': 'datetime2', 'DateTimeOffsetField': 'datetimeoffset', 'DecimalField': 'decimal(%(max_digits)s, %(decimal_places)s)', 'FileField': 'nvarchar(%(max_length)s)', 'FilePathField': 'nvarchar(%(max_length)s)', 'FloatField': 'double precision', 'GenericIPAddressField': 'nvarchar(39)', 'IntegerField': 'int', 'IPAddressField': 'nvarchar(15)', 'NullBooleanField': 'bit', 'OneToOneField': 'int', 'PositiveIntegerField': 'int', 'PositiveSmallIntegerField': 'smallint', 'SlugField': 'nvarchar(%(max_length)s)', 'SmallIntegerField': 'smallint', 'TextField': 'nvarchar(max)', 'TimeField': 'time', } # Starting with Django 1.7, check constraints are no longer included in with # the data_types value. data_type_check_constraints = { 'PositiveIntegerField': '%(qn_column)s >= 0', 'PositiveSmallIntegerField': '%(qn_column)s >= 0', } operators = { "exact": "= %s", "iexact": "LIKE %s ESCAPE '\\'", "contains": "LIKE %s ESCAPE '\\'", "icontains": "LIKE %s ESCAPE '\\'", "gt": "> %s", "gte": ">= %s", "lt": "< %s", "lte": "<= %s", "startswith": "LIKE %s ESCAPE '\\'", "endswith": "LIKE %s ESCAPE '\\'", "istartswith": "LIKE %s ESCAPE '\\'", "iendswith": "LIKE %s ESCAPE '\\'", } def __init__(self, *args, **kwargs): self.use_transactions = kwargs.pop('use_transactions', None) super(DatabaseWrapper, self).__init__(*args, **kwargs) try: self.command_timeout = int( self.settings_dict.get('COMMAND_TIMEOUT', 30)) except ValueError: self.command_timeout = 30 options = self.settings_dict.get('OPTIONS', {}) try: self.cast_avg_to_float = not bool( options.get('disable_avg_cast', False)) except ValueError: self.cast_avg_to_float = False self.features = DatabaseFeatures(self) self.ops = DatabaseOperations(self) self.client = BaseDatabaseClient(self) self.creation = DatabaseCreation(self) self.introspection = DatabaseIntrospection(self) self.validation = BaseDatabaseValidation(self) def init_connection_state(self): pass def disable_constraint_checking(self): """ Turn off constraint checking for every table """ cursor = self.cursor() cursor.execute( 'EXEC sp_MSforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"') return True def enable_constraint_checking(self): """ Turn on constraint checking for every table """ cursor = self.cursor() cursor.execute( 'EXEC sp_MSforeachtable "ALTER TABLE ? WITH NOCHECK CHECK CONSTRAINT all"' ) def check_constraints(self, table_names=None): """ Check the table constraints. """ cursor = self.cursor() if not table_names: cursor.execute('DBCC CHECKCONSTRAINTS WITH ALL_CONSTRAINTS') if cursor.description: raise DjangoIntegrityError(cursor.fetchall()) else: qn = self.ops.quote_name for name in table_names: cursor.execute( 'DBCC CHECKCONSTRAINTS({0}) WITH ALL_CONSTRAINTS'.format( qn(name))) if cursor.description: raise DjangoIntegrityError(cursor.fetchall()) # MS SQL Server doesn't support explicit savepoint commits; savepoints are # implicitly committed with the transaction. # Ignore them. def _savepoint_commit(self, sid): queries_log = self.queries if queries_log: queries_log.append({ 'sql': '-- RELEASE SAVEPOINT %s -- (because assertNumQueries)' % self.ops.quote_name(sid), 'time': '0.000', }) def is_usable(self): try: self.connection.cursor().execute("SELECT 1") except self.Error: return False else: return True def schema_editor(self, *args, **kwargs): return DatabaseSchemaEditor(self, *args, **kwargs)