Skip to content

Commit 4d29c60

Browse files
committed
Merge branch 'dev' of https://github.com/microsoft/mssql-django into django41
2 parents 279619f + 5a3458a commit 4d29c60

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

mssql/functions.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from django.db.models.expressions import Case, Exists, Expression, OrderBy, When, Window
1111
from django.db.models.fields import BinaryField, Field
1212
from django.db.models.functions import Cast, NthValue, MD5, SHA1, SHA224, SHA256, SHA384, SHA512
13-
from django.db.models.functions.math import ATan2, Ln, Log, Mod, Round
13+
from django.db.models.functions.math import ATan2, Ln, Log, Mod, Round, Degrees, Radians, Power
1414
from django.db.models.lookups import In, Lookup
1515
from django.db.models.query import QuerySet
1616
from django.db.models.sql.query import Query
@@ -43,6 +43,29 @@ def sqlserver_log(self, compiler, connection, **extra_context):
4343
def sqlserver_ln(self, compiler, connection, **extra_context):
4444
return self.as_sql(compiler, connection, function='LOG', **extra_context)
4545

46+
def sqlserver_degrees(self, compiler, connection, **extra_context):
47+
return self.as_sql(
48+
compiler, connection, function='DEGREES',
49+
template= 'DEGREES(CONVERT(float, %(expressions)s))',
50+
**extra_context
51+
)
52+
53+
def sqlserver_radians(self, compiler, connection, **extra_context):
54+
return self.as_sql(
55+
compiler, connection, function='RADIANS',
56+
template= 'RADIANS(CONVERT(float, %(expressions)s))',
57+
**extra_context
58+
)
59+
60+
def sqlserver_power(self, compiler, connection, **extra_context):
61+
expr = self.get_source_expressions()
62+
number_a = compiler.compile(expr[0])
63+
number_b = compiler.compile(expr[1])
64+
return self.as_sql(
65+
compiler, connection, function='POWER',
66+
template = 'POWER(CONVERT(float,{a}),{b})'.format(a=number_a[0], b=number_b[0]),
67+
**extra_context
68+
)
4669

4770
def sqlserver_mod(self, compiler, connection):
4871
# MSSQL doesn't have keyword MOD
@@ -391,6 +414,9 @@ def sqlserver_sha512(self, compiler, connection, **extra_context):
391414
key_transform_exact_process_rhs = KeyTransformExact.process_rhs
392415
KeyTransformExact.process_rhs = json_KeyTransformExact_process_rhs
393416
HasKeyLookup.as_microsoft = json_HasKeyLookup
417+
Degrees.as_microsoft = sqlserver_degrees
418+
Radians.as_microsoft = sqlserver_radians
419+
Power.as_microsoft = sqlserver_power
394420
Ln.as_microsoft = sqlserver_ln
395421
Log.as_microsoft = sqlserver_log
396422
Mod.as_microsoft = sqlserver_mod

testapp/settings.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,6 @@
137137
'schema.tests.SchemaTests.test_unique_together_with_fk_with_existing_index',
138138
'aggregation.tests.AggregateTestCase.test_count_star',
139139
'aggregation_regress.tests.AggregationTests.test_values_list_annotation_args_ordering',
140-
'db_functions.math.test_degrees.DegreesTests.test_integer',
141-
'db_functions.math.test_power.PowerTests.test_integer',
142-
'db_functions.math.test_radians.RadiansTests.test_integer',
143140
'db_functions.text.test_pad.PadTests.test_pad',
144141
'db_functions.text.test_replace.ReplaceTests.test_case_sensitive',
145142
'expressions.tests.FTimeDeltaTests.test_invalid_operator',

0 commit comments

Comments
 (0)