Skip to content

Commit c5ade68

Browse files
committed
Fix remaining flake8 errors
1 parent 762184a commit c5ade68

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

sql_server/pyodbc/operations.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ def _get_utcoffset(self, tzname):
2525
"""
2626
Returns UTC offset for given time zone in seconds
2727
"""
28-
# SQL Server has no built-in support for tz database
29-
# see http://blogs.msdn.com/b/sqlprogrammability/archive/2008/03/18/using-time-zone-data-in-sql-server-2008.aspx
28+
# SQL Server has no built-in support for tz database, see:
29+
# http://blogs.msdn.com/b/sqlprogrammability/archive/2008/03/18/using-time-zone-data-in-sql-server-2008.aspx
3030
zone = pytz.timezone(tzname)
3131
# no way to take DST into account at this point
3232
now = datetime.datetime.now()
@@ -179,7 +179,8 @@ def format_for_duration_arithmetic(self, sql):
179179
sql = '%%s'
180180
else:
181181
# use DATEADD twice to avoid arithmetic overflow for number part
182-
fmt = 'DATEADD(second, %s / 1000000%%s, DATEADD(microsecond, %s %%%%%%%% 1000000%%s, CAST(%%s AS datetime2)))'
182+
MICROSECOND = "DATEADD(microsecond, %s %%%%%%%% 1000000%%s, CAST(%%s AS datetime2))"
183+
fmt = 'DATEADD(second, %s / 1000000%%s, {})'.format(MICROSECOND)
183184
sql = (sql, sql)
184185
return fmt % sql
185186

@@ -336,8 +337,10 @@ def sql_flush(self, style, tables, sequences, allow_cascade=False):
336337
elem['start_id'] = 1
337338
elem.update(seq)
338339
seqs.append(elem)
340+
COLUMNS = "TABLE_NAME, CONSTRAINT_NAME"
341+
WHERE = "CONSTRAINT_TYPE not in ('PRIMARY KEY','UNIQUE')"
339342
cursor.execute(
340-
"SELECT TABLE_NAME, CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_TYPE not in ('PRIMARY KEY','UNIQUE')")
343+
"SELECT {} FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE {}".format(COLUMNS, WHERE))
341344
fks = cursor.fetchall()
342345
sql_list = ['ALTER TABLE %s NOCHECK CONSTRAINT %s;' %
343346
(self.quote_name(fk[0]), self.quote_name(fk[1])) for fk in fks]
@@ -379,7 +382,9 @@ def subtract_temporals(self, internal_type, lhs, rhs):
379382
sql = "CAST(DATEDIFF(day, %(rhs)s, %(lhs)s) AS bigint) * 86400 * 1000000"
380383
params = rhs_params + lhs_params
381384
else:
382-
sql = "CAST(DATEDIFF(second, %(rhs)s, %(lhs)s) AS bigint) * 1000000 + DATEPART(microsecond, %(lhs)s) - DATEPART(microsecond, %(rhs)s)"
385+
SECOND = "DATEDIFF(second, %(rhs)s, %(lhs)s)"
386+
MICROSECOND = "DATEPART(microsecond, %(lhs)s) - DATEPART(microsecond, %(rhs)s)"
387+
sql = "CAST({} AS bigint) * 1000000 + {}".format(SECOND, MICROSECOND)
383388
params = rhs_params + lhs_params * 2 + rhs_params
384389
return sql % {'lhs': lhs_sql, 'rhs': rhs_sql}, params
385390

test.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ python django/tests/runtests.py --settings=testapp.settings \
88
aggregation \
99
aggregation_regress \
1010
annotations \
11-
backends basic \
12-
bulk_create constraints \
11+
backends \
12+
basic \
13+
bulk_create \
14+
constraints \
1315
custom_columns \
1416
custom_lookups \
1517
custom_managers \

0 commit comments

Comments
 (0)