I'm using Devart components in Delphi XE10.2 VCL. I have a TMyQuery component with SQL code that includes the following:
Code: Select all
SELECT ... MOD((CellNbr - 1), :Columns) + 1 AS ColumnNbr FROM ...
where :Columns is an Integer input parameter. When I use the Field editor to "Add all fields", it adds ColumnNbr as a TLargeIntField, as I would expect, since MOD should return an integer result. The query executes in design mode, but when I run the app and activate it, I get a type mismatch error for field ColumnNbr: expecting 'LargeInt', actual: 'Float'. Why would this expression be returning a Float value instead of an integer?
Anticipating the question: yes, there are times when :Columns will be zero. In these cases, the expression returns NULL, which should be an acceptable value for a TLargeIntField.
If I manually change the ColumnNbr field to make it a TFloatField, the query works, as it does if I change the expression to read
Code: Select all
CAST(MOD((CellNbr - 1), :Columns) + 1 AS Integer) AS ColumnNbr
-- so I can work around the issue, but I'm curious to understand why it crops up in the first place.