ecpg - char as host var - Mailing list pgsql-novice

From J. Pablo González
Subject ecpg - char as host var
Date
Msg-id 000001cca49c$fc3f44c0$f4bdce40$@disablez.com
Whole thread Raw
List pgsql-novice

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.

pgsql-novice by date:

Previous
From: Johann Schatzer
Date:
Subject: How to truncate? integers
Next
From: Richard Broersma
Date:
Subject: Re: How to truncate? integers