Hi,

In the PostgreSQL Documentation, both ECPG PREPARE and SQL statement PREPARE 
can be used in ECPG [1].
However, SQL statement PREPARE does not work.

I wrote the source code as follows.

<test_app.pgc>
============================
  EXEC SQL PREPARE test_prep (int) AS SELECT id from test_table where id = $1;
  EXEC SQL EXECUTE test_prep (2);
============================

PostgreSQL 11.2 ECPG produced following code.

<test_app.c>
============================
  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "prepare \"test_prep\" ( int 
) as \" select id from test_table where id = $1 \"", ECPGt_EOIT, ECPGt_EORT);
#line 16 "test_app.pgc"

if (sqlca.sqlcode < 0) error_exit ( );}
#line 16 "test_app.pgc"

  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "test_prep", ECPGt_EOIT, 
ECPGt_EORT);
#line 17 "test_app.pgc"

if (sqlca.sqlcode < 0) error_exit ( );}
#line 17 "test_app.pgc"
============================


There are following problems.

(1)
When I run this program, it failed with "PostgreSQL error : -202[too few 
arguments on line 16]".
The reason is ECPGdo has no argument though prepare statement has "$1".

(2)
I want to execute test_prep (2), but ECPGst_execute does not have argument.


Can SQL statement PREPARE be really used in ECPG?


[1] - https://www.postgresql.org/docs/11/ecpg-sql-prepare.html


Regards,
Ryohei Takahashi


Reply via email to