Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
6c95b134
Kaydet (Commit)
6c95b134
authored
Eki 13, 2015
tarafından
Josh Smeaton
Kaydeden (comit)
Tim Graham
Eki 17, 2015
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #25517 -- Made Concat function idempotent on SQLite.
üst
0922bbf1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
7 deletions
+26
-7
functions.py
django/db/models/functions.py
+9
-6
1.8.6.txt
docs/releases/1.8.6.txt
+2
-0
tests.py
tests/db_functions/tests.py
+15
-1
No files found.
django/db/models/functions.py
Dosyayı görüntüle @
6c95b134
...
...
@@ -42,10 +42,10 @@ class ConcatPair(Func):
super
(
ConcatPair
,
self
)
.
__init__
(
left
,
right
,
**
extra
)
def
as_sqlite
(
self
,
compiler
,
connection
):
self
.
arg_joiner
=
' || '
self
.
template
=
'
%(expressions)
s
'
self
.
coalesce
()
return
super
(
ConcatPair
,
self
)
.
as_sql
(
compiler
,
connection
)
coalesced
=
self
.
coalesce
()
coalesced
.
arg_joiner
=
' ||
'
coalesced
.
template
=
'
%(expressions)
s'
return
super
(
ConcatPair
,
coalesced
)
.
as_sql
(
compiler
,
connection
)
def
as_mysql
(
self
,
compiler
,
connection
):
# Use CONCAT_WS with an empty separator so that NULLs are ignored.
...
...
@@ -55,9 +55,12 @@ class ConcatPair(Func):
def
coalesce
(
self
):
# null on either side results in null for expression, wrap with coalesce
c
=
self
.
copy
()
expressions
=
[
Coalesce
(
expression
,
Value
(
''
))
for
expression
in
self
.
get_source_expressions
()]
self
.
set_source_expressions
(
expressions
)
Coalesce
(
expression
,
Value
(
''
))
for
expression
in
c
.
get_source_expressions
()
]
c
.
set_source_expressions
(
expressions
)
return
c
class
Concat
(
Func
):
...
...
docs/releases/1.8.6.txt
Dosyayı görüntüle @
6c95b134
...
...
@@ -23,3 +23,5 @@ Bugfixes
have their reverse relations disabled (:ticket:`25545`).
* Allowed filtering over a ``RawSQL`` annotation (:ticket:`25506`).
* Made the ``Concat`` database function idempotent on SQLite (:ticket:`25517`).
tests/db_functions/tests.py
Dosyayı görüntüle @
6c95b134
...
...
@@ -7,7 +7,8 @@ from django.db import connection
from
django.db.models
import
CharField
,
TextField
,
Value
as
V
from
django.db.models.expressions
import
RawSQL
from
django.db.models.functions
import
(
Coalesce
,
Concat
,
Greatest
,
Least
,
Length
,
Lower
,
Now
,
Substr
,
Upper
,
Coalesce
,
Concat
,
ConcatPair
,
Greatest
,
Least
,
Length
,
Lower
,
Now
,
Substr
,
Upper
,
)
from
django.test
import
TestCase
,
skipIfDBFeature
,
skipUnlessDBFeature
from
django.utils
import
six
,
timezone
...
...
@@ -353,6 +354,19 @@ class FunctionTests(TestCase):
expected
=
article
.
title
+
' - '
+
article
.
text
self
.
assertEqual
(
expected
.
upper
(),
article
.
title_text
)
@skipUnless
(
connection
.
vendor
==
'sqlite'
,
"sqlite specific implementation detail."
)
def
test_concat_coalesce_idempotent
(
self
):
pair
=
ConcatPair
(
V
(
'a'
),
V
(
'b'
))
# Check nodes counts
self
.
assertEqual
(
len
(
list
(
pair
.
flatten
())),
3
)
self
.
assertEqual
(
len
(
list
(
pair
.
coalesce
()
.
flatten
())),
7
)
# + 2 Coalesce + 2 Value()
self
.
assertEqual
(
len
(
list
(
pair
.
flatten
())),
3
)
def
test_concat_sql_generation_idempotency
(
self
):
qs
=
Article
.
objects
.
annotate
(
description
=
Concat
(
'title'
,
V
(
': '
),
'summary'
))
# Multiple compilations should not alter the generated query.
self
.
assertEqual
(
str
(
qs
.
query
),
str
(
qs
.
all
()
.
query
))
def
test_lower
(
self
):
Author
.
objects
.
create
(
name
=
'John Smith'
,
alias
=
'smithj'
)
Author
.
objects
.
create
(
name
=
'Rhonda'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment