Thread: ecpg issue - not sending datatype to the backend

ecpg issue - not sending datatype to the backend

From
Mike Aubury
Date:
This is a little complex to explain - so its probably better with an example..

I don't know if theres some inbuilt function to tell you what datatype a value 
is - so 'kludged' this together : 

 CREATE OR REPLACE FUNCTION rval_type(m date) RETURNS text AS $$ BEGIN               RETURN 'it was a date'; END; $$
LANGUAGEplpgsql;
 
 CREATE OR REPLACE FUNCTION rval_type(m text) RETURNS text AS $$ BEGIN               RETURN 'it was a text'; END; $$
LANGUAGEplpgsql;
 
 CREATE OR REPLACE FUNCTION rval_type(m int) RETURNS text AS $$ BEGIN               RETURN 'it was a int'; END; $$
LANGUAGEplpgsql;
 




Now - if I have a cpc containing : 
  main() {  exec sql begin declare section;  date d;  int i;  char a[200];  char lv_out[200];  exec sql end declare
section;
  exec sql database test1;
  d=0;  i=0;  strcpy(a,"-");  memset(lv_out,0,sizeof(lv_out));

  exec sql select rval_type(:d) into :lv_out;  if (sqlca.sqlcode<0) sqlprint();  else printf("%s\n",lv_out);

  exec sql select rval_type(:i) into :lv_out;  if (sqlca.sqlcode<0) sqlprint();  else printf("%s\n",lv_out);
  exec sql select rval_type(:a) into :lv_out;  if (sqlca.sqlcode<0) sqlprint();  else printf("%s\n",lv_out);
  }



You can see I'm passing in a date, then an integer, then a character string. 
However - when you run the code you get : 

it was a text
it was a text
it was a text



This to me looks 'wrong', especially when previous versions of ecpg (<8.0?) 
gave the correct :

it was a date
it was a int
it was a text




Any thoughts ? 
(This is manifesting itself as arithmetic errors when I'm using dates in my 
application)





-- 
Mike Aubury

Aubit Computing Ltd is registered in England and Wales, Number: 3112827
Registered Address : Clayton House,59 Piccadilly,Manchester,M1 2AQ




Re: ecpg issue - not sending datatype to the backend

From
Michael Meskes
Date:
On Fri, May 02, 2008 at 02:28:31PM +0100, Mike Aubury wrote:
> Any thoughts ? 

As I already explained in private email ecpg uses an untyped statement
and data is always send as text. Of course this could be changed but
only by looking into the backend and asking what datatype this is. I
don't think it's a good idea to just expect people to use the same
datatype in C as in the backend. Keep in mind that this works the other
way round as well. All those people not using pgtypes will probably have
a string to hold the date in C. You can also use date in C but a string
in the database. I don't like the idea of forcing one way to the user,
especially with the current setup working most of the time and the
remaining ones just needing a cast.

Michael

P.S.: Nice move to go to the list in the middle of a discussion. You
could at least give me a chance to answer your email before going
public.

-- 
Michael Meskes
Email: Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org)
ICQ: 179140304, AIM/Yahoo: michaelmeskes, Jabber: meskes@jabber.org
Go VfL Borussia! Go SF 49ers! Use Debian GNU/Linux! Use PostgreSQL!