Subject fdb smallint ranges fails
Author Maximiliano Robaina
Hi,


I'm doing some tests on django-firebird (firebird backend for django) [1] and I see that inserting smallint data just on limit of the range fails


In Firebird technical specifications [2] the smallint range is -2^15 to 2^15-1 (-32768 to 32767).

but insert fails if I try to insert a record with a value -32768

Example:

CREATE TABLE MODEL_FIELDS_SMALLINTEGERMODEL
(
ID INTEGER NOT NULL,
"VALUE" SMALLINT NOT NULL,
CONSTRAINT INTEG_38 PRIMARY KEY (ID)
);


>>> conn = fdb.connect(dsn=....

>>> cur = conn.cursor()
>>> cur.execute('INSERT INTO "MODEL_FIELDS_SMALLINTEGERMODEL" ("VALUE") VALUES (?)', (-32768,))

Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/fdb/fbcore.py", line 3574, in execute
self._ps._execute(parameters)
File "/usr/local/lib/python2.7/dist-packages/fdb/fbcore.py", line 3258, in _execute
self.__Tuple2XSQLDA(self._in_sqlda, parameters)
File "/usr/local/lib/python2.7/dist-packages/fdb/fbcore.py", line 3044, in __Tuple2XSQLDA
sqlvar.sqlscale)
File "/usr/local/lib/python2.7/dist-packages/fdb/fbcore.py", line 2538, in _check_integer_range
raise ProgrammingError(msg, -802)
ProgrammingError: ('numeric overflow: value -32768\n (SMALLINT scaled for 0 decimal places) is of\n too great a magnitude to fit into its internal storage type SQL_SHORT,\n which has range [-32767,32767].', -802)

Why in fdb.ibase.py smaillint min range is defined as SHRT_MIN = -32767 ?
Is it just a mistake or is there another limitation?

Regards.
--
Maxi

[1] https://github.com/maxirobaina/django-firebird

[2] http://www.firebirdsql.org/en/firebird-technical-specifications/