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
f7467181
Kaydet (Commit)
f7467181
authored
May 19, 2013
tarafından
Aymeric Augustin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge pull request #1160 from erikr/host-inet-postgres2
Fixed #11442 -- Postgresql backend casts all inet types to text
üst
3d5a5462
60d94c2a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
17 additions
and
12 deletions
+17
-12
__init__.py
django/db/backends/__init__.py
+5
-5
base.py
django/db/backends/oracle/base.py
+1
-1
operations.py
django/db/backends/postgresql_psycopg2/operations.py
+2
-2
where.py
django/db/models/sql/where.py
+5
-3
tests.py
tests/string_lookup/tests.py
+4
-1
No files found.
django/db/backends/__init__.py
Dosyayı görüntüle @
f7467181
...
...
@@ -766,12 +766,12 @@ class BaseDatabaseOperations(object):
"""
return
cursor
.
fetchone
()[
0
]
def
field_cast_sql
(
self
,
db_type
):
def
field_cast_sql
(
self
,
db_type
,
internal_type
):
"""
Given a column type (e.g. 'BLOB', 'VARCHAR'),
returns the SQL necessary
to cast it before using it in a WHERE statement. Note that the
resulting string should contain a '
%
s' placeholder for the column be
ing
searched against.
Given a column type (e.g. 'BLOB', 'VARCHAR'),
and an internal type
(e.g. 'GenericIPAddressField'), returns the SQL necessary to cast it
before using it in a WHERE statement. Note that the resulting str
ing
s
hould contain a '
%
s' placeholder for the column being s
earched against.
"""
return
'
%
s'
...
...
django/db/backends/oracle/base.py
Dosyayı görüntüle @
f7467181
...
...
@@ -254,7 +254,7 @@ WHEN (new.%(col_name)s IS NULL)
def
fetch_returned_insert_id
(
self
,
cursor
):
return
int
(
cursor
.
_insert_id_var
.
getvalue
())
def
field_cast_sql
(
self
,
db_type
):
def
field_cast_sql
(
self
,
db_type
,
internal_type
):
if
db_type
and
db_type
.
endswith
(
'LOB'
):
return
"DBMS_LOB.SUBSTR(
%
s)"
else
:
...
...
django/db/backends/postgresql_psycopg2/operations.py
Dosyayı görüntüle @
f7467181
...
...
@@ -78,8 +78,8 @@ class DatabaseOperations(BaseDatabaseOperations):
return
lookup
def
field_cast_sql
(
self
,
db_type
):
if
db_type
==
'inet'
:
def
field_cast_sql
(
self
,
db_type
,
internal_type
):
if
internal_type
==
"GenericIPAddressField"
or
internal_type
==
"IPAddressField"
:
return
'HOST(
%
s)'
return
'
%
s'
...
...
django/db/models/sql/where.py
Dosyayı görüntüle @
f7467181
...
...
@@ -174,6 +174,8 @@ class WhereNode(tree.Node):
it.
"""
lvalue
,
lookup_type
,
value_annotation
,
params_or_value
=
child
field_internal_type
=
lvalue
.
field
.
get_internal_type
()
if
lvalue
.
field
else
None
if
isinstance
(
lvalue
,
Constraint
):
try
:
lvalue
,
params
=
lvalue
.
process
(
lookup_type
,
params_or_value
,
connection
)
...
...
@@ -187,7 +189,7 @@ class WhereNode(tree.Node):
if
isinstance
(
lvalue
,
tuple
):
# A direct database column lookup.
field_sql
,
field_params
=
self
.
sql_for_columns
(
lvalue
,
qn
,
connection
),
[]
field_sql
,
field_params
=
self
.
sql_for_columns
(
lvalue
,
qn
,
connection
,
field_internal_type
),
[]
else
:
# A smart object with an as_sql() method.
field_sql
,
field_params
=
lvalue
.
as_sql
(
qn
,
connection
)
...
...
@@ -257,7 +259,7 @@ class WhereNode(tree.Node):
raise
TypeError
(
'Invalid lookup_type:
%
r'
%
lookup_type
)
def
sql_for_columns
(
self
,
data
,
qn
,
connection
):
def
sql_for_columns
(
self
,
data
,
qn
,
connection
,
internal_type
=
None
):
"""
Returns the SQL fragment used for the left-hand side of a column
constraint (for example, the "T1.foo" portion in the clause
...
...
@@ -268,7 +270,7 @@ class WhereNode(tree.Node):
lhs
=
'
%
s.
%
s'
%
(
qn
(
table_alias
),
qn
(
name
))
else
:
lhs
=
qn
(
name
)
return
connection
.
ops
.
field_cast_sql
(
db_type
)
%
lhs
return
connection
.
ops
.
field_cast_sql
(
db_type
,
internal_type
)
%
lhs
def
relabel_aliases
(
self
,
change_map
):
"""
...
...
tests/string_lookup/tests.py
Dosyayı görüntüle @
f7467181
...
...
@@ -73,9 +73,11 @@ class StringLookupTests(TestCase):
"""
Regression test for #708
"like" queries on IP address fields require casting
to text
(on PostgreSQL).
"like" queries on IP address fields require casting
with HOST()
(on PostgreSQL).
"""
a
=
Article
(
name
=
'IP test'
,
text
=
'The body'
,
submitted_from
=
'192.0.2.100'
)
a
.
save
()
self
.
assertEqual
(
repr
(
Article
.
objects
.
filter
(
submitted_from__contains
=
'192.0.2'
)),
repr
([
a
]))
# Test that the searches do not match the subnet mask (/32 in this case)
self
.
assertEqual
(
Article
.
objects
.
filter
(
submitted_from__contains
=
'32'
)
.
count
(),
0
)
\ No newline at end of file
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