|
1 | 1 | from django.db.models.functions import Cast |
| 2 | +from django.db.models.functions.math import ATan2, Log, Ln, Round |
2 | 3 |
|
3 | 4 |
|
4 | 5 | class TryCast(Cast): |
5 | 6 | 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