RE: SQL statement PREPARE does not work in ECPG - Mailing list pgsql-hackers

From Takahashi, Ryohei
Subject RE: SQL statement PREPARE does not work in ECPG
Date
Msg-id EE586BE92A4AFB45B03310C2A0C0565D6D3817D2@G01JPEXMBKW03
Whole thread Raw
In response to Re: SQL statement PREPARE does not work in ECPG  (Michael Meskes <meskes@postgresql.org>)
Responses Re: SQL statement PREPARE does not work in ECPG
List pgsql-hackers
Hi Meskes-san,


> Ah right, my bad. The workaround should have been:

Thank you. It works.


> As for the PREPARE statement itself, could you try the attached small
> patch please.

It works well for my statement
"EXEC SQL PREPARE test_prep (int) AS SELECT id from test_table where id = $1;".

However, since data type information is not used, it does not works well
for prepare statements which need data type information such as 
"EXEC SQL PREPARE test_prep (int, int) AS SELECT $1 + $2;".

It fails with "PostgreSQL error : -400[operator is not unique: unknown + unknown on line 20]".

(Of course, "EXEC SQL PREPARE test_prep AS SELECT $1::int + $2::int;" works well.)


> Could you please also verify for me if this works correctly if you use
> a variable instead of the const? As in:

> EXEC SQL BEGIN DECLARE SECTION;
> int i=2;
> EXEC SQL END DECLARE SECTION;
> ...
> EXEC SQL EXECUTE test_prep (:i);

It also works.
(Actually, I wrote "EXEC SQL EXECUTE test_prep (:i) INTO :ID;".)

ECPG produced as follows.

============================
ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "test_prep",
        ECPGt_int,&(i),(long)1,(long)1,sizeof(int),
        ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
        ECPGt_int,&(ID),(long)1,(long)1,sizeof(int),
        ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
============================


Regards,
Ryohei Takahashi


pgsql-hackers by date:

Previous
From: Thomas Munro
Date:
Subject: Vectors instead of lists, specialised qsort(), binary_search(), unique()
Next
From: "Ideriha, Takeshi"
Date:
Subject: RE: Protect syscache from bloating with negative cache entries