Skip to content

Commit 3f3898a

Browse files
committed
Fix ATan2, Log, Ln and Round
1 parent 4f302e0 commit 3f3898a

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

sql_server/pyodbc/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import sql_server.pyodbc.functions # noqa

sql_server/pyodbc/functions.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
from django.db.models.functions import Cast
2+
from django.db.models.functions.math import ATan2, Log, Ln, Round
23

34

45
class TryCast(Cast):
56
function = 'TRY_CAST'
7+
8+
9+
def sqlserver_atan2(self, compiler, connection, **extra_context):
10+
return self.as_sql(compiler, connection, function='ATN2', **extra_context)
11+
12+
13+
def sqlserver_log(self, compiler, connection, **extra_context):
14+
clone = self.copy()
15+
clone.set_source_expressions(self.get_source_expressions()[::-1])
16+
return clone.as_sql(compiler, connection, **extra_context)
17+
18+
19+
def sqlserver_ln(self, compiler, connection, **extra_context):
20+
return self.as_sql(compiler, connection, function='LOG', **extra_context)
21+
22+
23+
def sqlserver_round(self, compiler, connection, **extra_context):
24+
return self.as_sql(compiler, connection, template='%(function)s(%(expressions)s, 0)', **extra_context)
25+
26+
27+
ATan2.as_microsoft = sqlserver_atan2
28+
Log.as_microsoft = sqlserver_log
29+
Ln.as_microsoft = sqlserver_ln
30+
Round.as_microsoft = sqlserver_round

0 commit comments

Comments
 (0)