#27397: Querying with an integer larger than SQLite supports crashes with
OverflowError
-------------------------------------+-------------------------------------
     Reporter:  Ramin Farajpour      |                    Owner:  Ramin
  Cami                               |  Farajpour Cami
         Type:  Bug                  |                   Status:  assigned
    Component:  Database layer       |                  Version:  1.10
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  SQLite, Error        |             Triage Stage:  Accepted
  Handling                           |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Ramin Farajpour Cami):

 {{{
 >CREATE TABLE numbers (i INTEGER, r REAL, t TEXT, b BLOB);

 >INSERT INTO numbers VALUES (9223372036854775807, 9223372036854775807,
 9223372036854775807, 9223372036854775807);

 > SELECT * FROM numbers;
 i                     r                     t                     b
 --------------------  --------------------  --------------------
 --------------------
 9223372036854775807   9.22337203685478e+18  9223372036854775807
 9223372036854775807

 > SELECT typeof(i),typeof(r),typeof(t),typeof(b) FROM numbers;
 typeof(i)   typeof(r)   typeof(t)   typeof(b)
 ----------  ----------  ----------  ----------
 integer     real        text        integer

 > SELECT i+1,r+1,t+1,b+1 FROM numbers;
 i+1                   r+1                   t+1                   b+1
 --------------------  --------------------  --------------------
 --------------------
 -9223372036854775808  9.22337203685478e+18  -9223372036854775808
 -9223372036854775808

 }}}

 you see shift +1 and `-9223372036854775808`

 INTEGER. The value is a signed integer, stored in 1, 2, 3, 4, 6, or 8
 bytes depending on the magnitude of the value.

 That is, you can only store values from `-2**63` to `(2**63-1) `

 Be careful when you need to store large numbers in SQLite. If you really
 need to support unsigned 64-bit numbers, ?? but it makes a SQLite bad
 choice for developing

 please look :
 https://github.com/python/cpython/blob/master/Modules/_sqlite/util.c#L129&L153

--
Ticket URL: <https://code.djangoproject.com/ticket/27397#comment:24>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.31233b14fdc85b73082243fb08af2b3f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to