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
1c12df4a
Kaydet (Commit)
1c12df4a
authored
Ara 14, 2015
tarafından
anabelensc
Kaydeden (comit)
Tim Graham
Ock 03, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #25912 -- Added binary left/right shift operators to F expressions.
Thanks Mariusz Felisiak for review and MySQL advice.
üst
f0ef0c49
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
37 additions
and
5 deletions
+37
-5
AUTHORS
AUTHORS
+1
-0
operations.py
django/db/backends/mysql/operations.py
+4
-1
operations.py
django/db/backends/oracle/operations.py
+5
-2
expressions.py
django/db/models/expressions.py
+8
-0
1.11.txt
docs/releases/1.11.txt
+3
-0
queries.txt
docs/topics/db/queries.txt
+6
-2
tests.py
tests/expressions/tests.py
+10
-0
No files found.
AUTHORS
Dosyayı görüntüle @
1c12df4a
...
...
@@ -42,6 +42,7 @@ answer newbie questions, and generally made Django that much better:
Amit Ramon <amit.ramon@gmail.com>
Amit Upadhyay <http://www.amitu.com/blog/>
A. Murat Eren <meren@pardus.org.tr>
Ana Belen Sarabia <belensarabia@gmail.com>
Ana Krivokapic <https://github.com/infraredgirl>
Andi Albrecht <albrecht.andi@gmail.com>
André Ericson <de.ericson@gmail.com>
...
...
django/db/backends/mysql/operations.py
Dosyayı görüntüle @
1c12df4a
...
...
@@ -203,8 +203,11 @@ class DatabaseOperations(BaseDatabaseOperations):
return
'POW(
%
s)'
%
','
.
join
(
sub_expressions
)
# Convert the result to a signed integer since MySQL's binary operators
# return an unsigned integer.
elif
connector
in
(
'&'
,
'|'
):
elif
connector
in
(
'&'
,
'|'
,
'<<'
):
return
'CONVERT(
%
s, SIGNED)'
%
connector
.
join
(
sub_expressions
)
elif
connector
==
'>>'
:
lhs
,
rhs
=
sub_expressions
return
'FLOOR(
%(lhs)
s / POW(2,
%(rhs)
s))'
%
{
'lhs'
:
lhs
,
'rhs'
:
rhs
}
return
super
(
DatabaseOperations
,
self
)
.
combine_expression
(
connector
,
sub_expressions
)
def
get_db_converters
(
self
,
expression
):
...
...
django/db/backends/oracle/operations.py
Dosyayı görüntüle @
1c12df4a
...
...
@@ -436,14 +436,17 @@ WHEN (new.%(col_name)s IS NULL)
value
.
second
,
value
.
microsecond
)
def
combine_expression
(
self
,
connector
,
sub_expressions
):
"Oracle requires special cases for
%%
and & operators in query expressions"
lhs
,
rhs
=
sub_expressions
if
connector
==
'
%%
'
:
return
'MOD(
%
s)'
%
','
.
join
(
sub_expressions
)
elif
connector
==
'&'
:
return
'BITAND(
%
s)'
%
','
.
join
(
sub_expressions
)
elif
connector
==
'|'
:
lhs
,
rhs
=
sub_expressions
return
'BITAND(-
%(lhs)
s-1,
%(rhs)
s)+
%(lhs)
s'
%
{
'lhs'
:
lhs
,
'rhs'
:
rhs
}
elif
connector
==
'<<'
:
return
'(
%(lhs)
s * POWER(2,
%(rhs)
s))'
%
{
'lhs'
:
lhs
,
'rhs'
:
rhs
}
elif
connector
==
'>>'
:
return
'FLOOR(
%(lhs)
s / POWER(2,
%(rhs)
s))'
%
{
'lhs'
:
lhs
,
'rhs'
:
rhs
}
elif
connector
==
'^'
:
return
'POWER(
%
s)'
%
','
.
join
(
sub_expressions
)
return
super
(
DatabaseOperations
,
self
)
.
combine_expression
(
connector
,
sub_expressions
)
...
...
django/db/models/expressions.py
Dosyayı görüntüle @
1c12df4a
...
...
@@ -30,6 +30,8 @@ class Combinable(object):
# usage.
BITAND
=
'&'
BITOR
=
'|'
BITLEFTSHIFT
=
'<<'
BITRIGHTSHIFT
=
'>>'
def
_combine
(
self
,
other
,
connector
,
reversed
,
node
=
None
):
if
not
hasattr
(
other
,
'resolve_expression'
):
...
...
@@ -76,6 +78,12 @@ class Combinable(object):
def
bitand
(
self
,
other
):
return
self
.
_combine
(
other
,
self
.
BITAND
,
False
)
def
bitleftshift
(
self
,
other
):
return
self
.
_combine
(
other
,
self
.
BITLEFTSHIFT
,
False
)
def
bitrightshift
(
self
,
other
):
return
self
.
_combine
(
other
,
self
.
BITRIGHTSHIFT
,
False
)
def
__or__
(
self
,
other
):
raise
NotImplementedError
(
"Use .bitand() and .bitor() for bitwise logical operations."
...
...
docs/releases/1.11.txt
Dosyayı görüntüle @
1c12df4a
...
...
@@ -367,6 +367,9 @@ Models
:meth:`~django.db.models.Expression.desc` to control
the ordering of null values.
* The new ``F`` expression ``bitleftshift()`` and ``bitrightshift()`` methods
allow :ref:`bitwise shift operations <using-f-expressions-in-filters>`.
Requests and Responses
~~~~~~~~~~~~~~~~~~~~~~
...
...
docs/topics/db/queries.txt
Dosyayı görüntüle @
1c12df4a
...
...
@@ -652,11 +652,15 @@ that were modified more than 3 days after they were published::
>>> from datetime import timedelta
>>> Entry.objects.filter(mod_date__gt=F('pub_date') + timedelta(days=3))
The ``F()`` objects support bitwise operations by ``.bitand()``
and
``.bit
or()``, f
or example::
The ``F()`` objects support bitwise operations by ``.bitand()``
, ``.bitor()``,
``.bit
rightshift()``, and ``.bitleftshift()``. F
or example::
>>> F('somefield').bitand(16)
.. versionchanged:: 1.11
Support for ``.bitrightshift()`` and ``.bitleftshift()`` was added.
The ``pk`` lookup shortcut
--------------------------
...
...
tests/expressions/tests.py
Dosyayı görüntüle @
1c12df4a
...
...
@@ -745,6 +745,16 @@ class ExpressionOperatorTests(TestCase):
self
.
assertEqual
(
Number
.
objects
.
get
(
pk
=
self
.
n1
.
pk
)
.
integer
,
-
64
)
self
.
assertEqual
(
Number
.
objects
.
get
(
pk
=
self
.
n
.
pk
)
.
float
,
Approximate
(
15.500
,
places
=
3
))
def
test_lefthand_bitwise_left_shift_operator
(
self
):
Number
.
objects
.
update
(
integer
=
F
(
'integer'
)
.
bitleftshift
(
2
))
self
.
assertEqual
(
Number
.
objects
.
get
(
pk
=
self
.
n
.
pk
)
.
integer
,
168
)
self
.
assertEqual
(
Number
.
objects
.
get
(
pk
=
self
.
n1
.
pk
)
.
integer
,
-
168
)
def
test_lefthand_bitwise_right_shift_operator
(
self
):
Number
.
objects
.
update
(
integer
=
F
(
'integer'
)
.
bitrightshift
(
2
))
self
.
assertEqual
(
Number
.
objects
.
get
(
pk
=
self
.
n
.
pk
)
.
integer
,
10
)
self
.
assertEqual
(
Number
.
objects
.
get
(
pk
=
self
.
n1
.
pk
)
.
integer
,
-
11
)
def
test_lefthand_bitwise_or
(
self
):
# LH Bitwise or on integers
Number
.
objects
.
update
(
integer
=
F
(
'integer'
)
.
bitor
(
48
))
...
...
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