1+ from itertools import chain
2+
13from django .db .models .aggregates import Avg , Count , StdDev , Variance
24from django .db .models .expressions import Ref , Value
35from django .db .models .functions import ConcatPair , Greatest , Least , Length , Substr
@@ -13,8 +15,7 @@ def _as_sql_agv(self, compiler, connection):
1315def _as_sql_concatpair (self , compiler , connection ):
1416 if connection .sql_server_version < 2012 :
1517 node = self .coalesce ()
16- node .arg_joiner = ' + '
17- return node .as_sql (compiler , connection , template = '%(expressions)s' )
18+ return node .as_sql (compiler , connection , arg_joiner = ' + ' , template = '%(expressions)s' )
1819 else :
1920 return self .as_sql (compiler , connection )
2021
@@ -25,17 +26,15 @@ def _as_sql_greatest(self, compiler, connection):
2526 # SQL Server does not provide GREATEST function,
2627 # so we emulate it with a table value constructor
2728 # https://msdn.microsoft.com/en-us/library/dd776382.aspx
28- self .arg_joiner = '), ('
2929 template = '(SELECT MAX(value) FROM (VALUES (%(expressions)s)) AS _%(function)s(value))'
30- return self .as_sql (compiler , connection , template = template )
30+ return self .as_sql (compiler , connection , arg_joiner = '), (' , template = template )
3131
3232def _as_sql_least (self , compiler , connection ):
3333 # SQL Server does not provide LEAST function,
3434 # so we emulate it with a table value constructor
3535 # https://msdn.microsoft.com/en-us/library/dd776382.aspx
36- self .arg_joiner = '), ('
3736 template = '(SELECT MIN(value) FROM (VALUES (%(expressions)s)) AS _%(function)s(value))'
38- return self .as_sql (compiler , connection , template = template )
37+ return self .as_sql (compiler , connection , arg_joiner = '), (' , template = template )
3938
4039def _as_sql_length (self , compiler , connection ):
4140 return self .as_sql (compiler , connection , function = 'LEN' )
@@ -275,8 +274,9 @@ def as_sql(self):
275274 if self .return_id and self .connection .features .can_return_id_from_insert :
276275 result .insert (0 , 'SET NOCOUNT ON' )
277276 result .append ((values_format + ';' ) % ', ' .join (placeholder_rows [0 ]))
278- result .append ('SELECT CAST(SCOPE_IDENTITY() AS int)' )
279- return [(" " .join (result ), tuple (param_rows [0 ]))]
277+ params = [param_rows [0 ]]
278+ result .append ('SELECT CAST(SCOPE_IDENTITY() AS bigint)' )
279+ return [(" " .join (result ), tuple (chain .from_iterable (params )))]
280280
281281 if can_bulk :
282282 result .append (self .connection .ops .bulk_insert_sql (fields , placeholder_rows ))
0 commit comments