big int to ESQL
Posted in 2003
Topics: Stored Procedures & SPL, Connectivity: ODBC / JDBC / .NET, Connectivity: ESQL/C, 4GL & Embedded SQL, Data Types & Schema Design, Java & JDBC Development, Versions, Editions & End-of-Life
As I mentioned earlier, we are in the process of porting a SQL Server
application to Informix. SQL Server has a data type bigint which corresponds
to int8 of Informix. They both take 8 bytes and can take upto 2^63-1 value.
I believe that value is 4611686018427387905.
We use two languages for development. C++ and Java. A Java long is machine
independent and the MAX_VALUE for it is higher than 4611686018427387905.
So that is not a problem.
In C++, a long long variable can take the above value. We are using
ODBC connection to SQL Server. However at this time we are planning to
use ESQL/C for Informix. What I am finding it difficult is that ESQL
rejects long long variable declaration.
For e.g.
$ long long myvar ;
gives compliation error.
I know int8 in informix is machine independent and is a struct and ESQL/C
is suppose to use that struct. But that would mean a huge change in our
code. So I have written a small function to convert int8 to a long long value.
create function biginttochar(p_int8 int8) returning char(19) ; define w char(19);
let w = p_int8 ;
return w ;
end function ;
In ESQL/C
$ long myvar ;
$ select biginttochar(fld1)
into :myvar
from ...
works fine till the value of fld1 is 2^31-1 which is 2,147,483,647.
After that it spews error -1215.
So how to declare a long long int in ESQL/C.
IDS 9.21.UC4
ESQL: 9.16.UC1
thanks.
rkusenet wrote:
> As I mentioned earlier, we are in the process of porting a SQL Server
> application to Informix. SQL Server has a data type bigint which corresponds
> to int8 of Informix. They both take 8 bytes and can take upto 2^63-1 value.
> I believe that value is 4611686018427387905.
>
> We use two languages for development. C++ and Java. A Java long is machine
> independent and the MAX_VALUE for it is higher than 4611686018427387905.
> So that is not a problem.
>
> In C++, a long long variable can take the above value. We are using
> ODBC connection to SQL Server. However at this time we are planning to
> use ESQL/C for Informix. What I am finding it difficult is that ESQL
> rejects long long variable declaration.
>
> For e.g.
> $ long long myvar ;>
> gives compliation error.
Right - it isn't documented that ESQL/C understands long long, and it
doesn't.
> I know int8 in informix is machine independent and is a struct and ESQL/C
> is suppose to use that struct. But that would mean a huge change in our
> code. So I have written a small function to convert int8 to a long long value.
>
> create function biginttochar(p_int8 int8) returning char(19) ;> define w char(19);
> let w = p_int8 ;
> return w ;
> end function ;
>
> In ESQL/C
>
> $ long myvar ;>
> $ select biginttochar(fld1)
> into :myvar
> from ...>
> works fine till the value of fld1 is 2^31-1 which is 2,147,483,647.
> After that it spews error -1215.
>
> So how to declare a long long int in ESQL/C.
>
> IDS 9.21.UC4
> ESQL: 9.16.UC1
You need to upgrade your ESQL/C - not because it provides a solution
to the problem, per se, but simply because 9.16 is very old (and 9.21
is not very current either - consider an upgrade for that, too).
You have to use either ifx_int8_t structures, or you have to use
DECIMAL(19) or larger. Both work. You then have to separately write
code to stuff that into a long long, or to stuff a long long into the
other value. The ifx_int8_t was introduced a year or two before
64-bit integers became ubiquitous. In theory, you should be able to
convert an ifx_int8_t into a long long and vice versa with a little
bit twiddling. I haven't done the experimentation to find out which
of the two 32-bit integers contains 32 bits of data and which contains
31, but the sign information is stored in the spare 2-byte (short)
value in the structure.
--
Jonathan Leffler #include <disclaimer.h>
Email: jleffler@earthlink.net, jleffler@us.ibm.com
Guardian of DBD::Informix v2003.04 -- http://dbi.perl.org/