Thread: ecpg - char as host var
Hi,
I’m in the process of adding postgresql support to a big legacy program which stores small values in int8 (which is a typedef for a signed char).
However, when retrieving the value from a numeric(x) column , ecpg debug shows I get the correct value (e.g. 1), but in the int8 host variable I get the ascii value (49).
So basically the program goes like…
[.h file]
typedef char int8;
[.c file]
exec sql type int8 is char;
exec sql begin declare section;
int8 myvar;
exec sql end declare section;
exec sql select my_integer(1) column into :myvar from my_table;
And… I cannot change the int8 type (.h files are provided to me, structures cannot be modified), and there’s an epic amount of this cases so converting them all to use proper short ints for redaing/writing into the database would take too much time.
So… is there a decent solution to this ? So far I tried lying in the exec sql type sentence and telling that int8 is a short int… which somehow seems to work, but I wouldn’t want it to cause problems down the road.