|
10 | 10 | from django.db.models.expressions import Case, Exists, Expression, OrderBy, When, Window
|
11 | 11 | from django.db.models.fields import BinaryField, Field
|
12 | 12 | 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 |
14 | 14 | from django.db.models.lookups import In, Lookup
|
15 | 15 | from django.db.models.query import QuerySet
|
16 | 16 | from django.db.models.sql.query import Query
|
@@ -43,6 +43,29 @@ def sqlserver_log(self, compiler, connection, **extra_context):
|
43 | 43 | def sqlserver_ln(self, compiler, connection, **extra_context):
|
44 | 44 | return self.as_sql(compiler, connection, function='LOG', **extra_context)
|
45 | 45 |
|
| 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 | + ) |
46 | 69 |
|
47 | 70 | def sqlserver_mod(self, compiler, connection):
|
48 | 71 | # MSSQL doesn't have keyword MOD
|
@@ -391,6 +414,9 @@ def sqlserver_sha512(self, compiler, connection, **extra_context):
|
391 | 414 | key_transform_exact_process_rhs = KeyTransformExact.process_rhs
|
392 | 415 | KeyTransformExact.process_rhs = json_KeyTransformExact_process_rhs
|
393 | 416 | HasKeyLookup.as_microsoft = json_HasKeyLookup
|
| 417 | +Degrees.as_microsoft = sqlserver_degrees |
| 418 | +Radians.as_microsoft = sqlserver_radians |
| 419 | +Power.as_microsoft = sqlserver_power |
394 | 420 | Ln.as_microsoft = sqlserver_ln
|
395 | 421 | Log.as_microsoft = sqlserver_log
|
396 | 422 | Mod.as_microsoft = sqlserver_mod
|
|
0 commit comments