Commits

Mikhail Denisenko committed 43f87d5 Merge

merge with default

Comments (0)

Files changed (10)

 
 set django_branch=stable/%DJANGO_VER%.x
 
-if not exist env\src\django call git clone https://github.com/django/django.git -b %django_branch% env/src/django
+if not exist env\src\django call git clone https://github.com/denisenkom/django.git -b %django_branch% env/src/django
 pushd env\src\django
 call git pull
 popd
 python tests\test_main\manage.py test --noinput
 
 set PYTHONPATH=.
-python env\src\django\tests\runtests.py --noinput --settings=django_settings
+python env\src\django\tests\runtests.py --noinput --settings=django_settings --liveserver=localhost:8200-8300
 django_branch=stable/${DJANGO_VER}.x
 
 if [ ! -d env/src/django ]; then
-    git clone https://github.com/django/django.git -b $django_branch env/src/django
+    git clone https://github.com/denisenkom/django.git -b $django_branch env/src/django
 fi
 pushd env/src/django
 git pull
 #python tests/test_stardardapps/manage.py test --noinput
 
 # run django test suite
-env PYTHONPATH=. python env/src/django/tests/runtests.py --noinput --settings=django_settings
+env PYTHONPATH=. python env/src/django/tests/runtests.py --noinput --settings=django_settings --liveserver=localhost:8200-8300

django_settings.py

 
 options = {'use_mars': True,
            'allow_nulls_in_unique_constraints': False,  # sqlserver doesn't fully support multiple nulls in unique constraint
+           'extra_params': 'MARS Connection=True;',
            }
 
+DATABASE_HOST = os.environ['HOST'] + '\\' + os.environ.get('SQLINSTANCE', '')
+
 DATABASES = {
     'default': {
         'ENGINE': os.environ['BACKEND'],
-        'HOST': os.environ['HOST'],
+        'HOST': DATABASE_HOST,
         'NAME': os.environ['DATABASE_NAME'] + '_default',
         'USER': os.environ['SQLUSER'],
         'PASSWORD': os.environ['SQLPASSWORD'],
         },
     'other': {
         'ENGINE': os.environ['BACKEND'],
-        'HOST': os.environ['HOST'],
+        'HOST': DATABASE_HOST,
         'NAME': os.environ['DATABASE_NAME'] + '_other',
         'USER': os.environ['SQLUSER'],
         'PASSWORD': os.environ['SQLPASSWORD'],

sqlserver/ado/base.py

 
     # If no user is specified, use integrated security.
     if settings.USER != '':
-        auth_string = 'UID={0};PWD={1}'.format(settings.USER, settings.PASSWORD)
+        user = settings.USER
+        if isinstance(user, bytes):
+            user = user.decode('utf8')
+        password = settings.PASSWORD
+        if isinstance(password, bytes):
+            password = password.decode('utf8')
+        auth_string = u'UID={0};PWD={1}'.format(user, password)
     else:
         auth_string = 'Integrated Security=SSPI'
 

sqlserver/ado/dbapi.py

 
     if isinstance(value, basestring):
         p.Value = value
-        p.Size = len(value)
+        #p.Size = len(value)
 
     elif isinstance(value, buffer):
         p.Size = len(value)
             p.Precision = digit_count + exponent
 
     elif isinstance(value, datetime.time):
+            if getattr(settings, 'USE_TZ', False) and value.tzinfo:
+                value = value.astimezone(timezone.utc)
             p.Value = datetime.datetime(1,1,1, value.hour, value.minute, value.second)
+    elif isinstance(value, datetime.datetime):
+            if getattr(settings, 'USE_TZ', False) and value.tzinfo:
+                value = value.astimezone(timezone.utc)
+            p.Value = value
     else:
         # For any other type, set the value and let pythoncom do the right thing.
         p.Value = value
             self._description_from_recordset(recordset[0])
         except Exception as e:
             _message = ""
-            if hasattr(e, 'args'): _message += str(e.args)+"\n"
-            _message += "Command:\n%s\nParameters:\n%s" %  (self.cmd.CommandText, format_parameters(self.cmd.Parameters, True))
+            if hasattr(e, 'args'): _message += str(e.args)
+            #_message += "Command:\n%s\nParameters:\n%s" %  (self.cmd.CommandText, format_parameters(self.cmd.Parameters, True))
             klass = self.connection._suggest_error_class()
             self._raiseCursorError(klass, _message)
 
         """
         self.messages = list()
         if self.connection is None or self.rs is None:
-            self._raiseCursorError(Error, None)
+            #self._raiseCursorError(Error, None)
             return None
 
         recordset = self.rs.NextRecordset()[0]
         (adBoolean,): bool,
         adoLongTypes+adoRowIdTypes : long,
         adoIntegerTypes: int,
-        adoBinaryTypes: buffer, 
+        adoBinaryTypes: buffer,
     }, 
     lambda x: x)
 

sqlserver/ado/introspection.py

         ado_consts.adDouble: 'FloatField',
         ado_consts.adSingle: 'FloatField',
         ado_consts.adInteger: 'IntegerField',
-        ado_consts.adBigInt: 'IntegerField',
-        #ado_consts.adBigInt: 'BigIntegerField',
+        ado_consts.adBigInt: 'BigIntegerField',
         ado_consts.adSmallInt: 'IntegerField',
         ado_consts.adTinyInt: 'IntegerField',
         ado_consts.adVarChar: 'CharField',

sqlserver/base.py

 
     ignores_nulls_in_unique_constraints = False
     allows_group_by_pk = False
+    allows_group_by_ordinal = False
     supports_microsecond_precision = False
     supports_subqueries_in_group_by = False
     allow_sliced_subqueries = False
         # The OUTPUT clause is supported in 2005+ sql servers
         self.features.can_return_id_from_insert = self._is_sql2005_and_up(conn)
         self.features.has_bulk_insert = self._is_sql2008_and_up(conn)
-        if not type(self).__module__.startswith('sqlserver.pymssql.'):
-            # pymssql doesn't support new sql server date types
-            self.features.supports_microsecond_precision = self._is_sql2008_and_up(conn)
-            self.creation._patch_for_sql2008_and_up()
-        if self.settings_dict["OPTIONS"].get("allow_nulls_in_unique_constraints", True):
+        if type(self).__module__.startswith('sqlserver.pytds.'):
+            # only pytds support new sql server date types
+            supports_new_date_types = self._is_sql2008_and_up(conn)
+            self.features.supports_microsecond_precision = supports_new_date_types
+            if supports_new_date_types:
+                self.creation._patch_for_sql2008_and_up()
+        if settings_dict["OPTIONS"].get("allow_nulls_in_unique_constraints", True):
             self.features.ignores_nulls_in_unique_constraints = self._is_sql2008_and_up(conn)
             if self._is_sql2008_and_up(conn):
                 self.creation.sql_create_model = self.creation.sql_create_model_sql2008
             cursor = self.connection.cursor()
         else:
             cursor = self._cursor()
-        cursor.execute('EXEC sp_MSforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"')
+        cursor.execute("EXEC sp_MSforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT all'")
+        # this breakes test on ado, see Issue #2
+        while cursor.nextset():
+            pass
         cursor.close()
         return True
 
             cursor = self.connection.cursor()
         else:
             cursor = self._cursor()
-        cursor.execute('EXEC sp_MSforeachtable "ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all"')
+        cursor.execute("EXEC sp_MSforeachtable 'ALTER TABLE ? WITH NOCHECK CHECK CONSTRAINT all'")
+        # this breakes test on ado, see Issue #2
+        while cursor.nextset():
+            pass
         cursor.close()
 
     def check_constraints(self, table_names=None):
             cursor = self._cursor()
         if not table_names:
             cursor.execute('DBCC CHECKCONSTRAINTS WITH ALL_CONSTRAINTS')
+            if cursor.description:
+                raise utils.IntegrityError(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 utils.IntegrityError(cursor.fetchall())
+                if cursor.description:
+                    raise utils.IntegrityError(cursor.fetchall())

sqlserver/creation.py

         sql = 'CREATE ASSEMBLY regex_clr FROM 0x' + assembly
         cursor = self.connection.cursor()
         try:
-            cursor.execute('USE [{}]'.format(test_database_name))
+            cursor.execute('USE [{0}]'.format(test_database_name))
             cursor.execute(sql)
             cursor.execute('''
             create function REGEXP_LIKE
                 fix_fields.append(f)
                 f._unique = False
         for field_constraints in opts.unique_together:
-            predicate_parts = ['[{}] '.format(opts.get_field(f).column) + style.SQL_KEYWORD('IS NOT NULL')
+            predicate_parts = ['[{0}] '.format(opts.get_field(f).column) + style.SQL_KEYWORD('IS NOT NULL')
                                for f in field_constraints if opts.get_field(f).null]
             index_name = 'UX_{table}_{columns}'.format(
                 table=opts.db_table,

sqlserver/introspection.py

 join INFORMATION_SCHEMA.KEY_COLUMN_USAGE fk_cols
 	on ref_const.CONSTRAINT_NAME = fk_cols.CONSTRAINT_NAME
 
-Join INFORMATION_SCHEMA.KEY_COLUMN_USAGE pk_cols
+join INFORMATION_SCHEMA.KEY_COLUMN_USAGE pk_cols
 	on pk.CONSTRAINT_NAME = pk_cols.CONSTRAINT_NAME
 where
 	fk.TABLE_NAME = %s"""

sqlserver/pytds/base.py

 
 from .introspection import DatabaseIntrospection
 
+Database = pytds
+
+def utc_tzinfo_factory(offset):
+    if offset != 0:
+        raise AssertionError("database connection isn't set to UTC")
+    return utc
+
 class DatabaseWrapper(SqlServerBaseWrapper):
     Database = pytds
 
     def _cursor(self):
         if self.connection is None:
             self.connection = self.get_new_connection(self.settings_dict)
-        return CursorWrapper(self.connection.cursor())
+        cursor = self.connection.cursor()
+        cursor.tzinfo_factory = utc_tzinfo_factory if settings.USE_TZ else None
+        return CursorWrapper(cursor)
 
     def _set_autocommit(self, autocommit):
         self.connection.autocommit = autocommit