RE: SQL statement PREPARE does not work in ECPG

From: "Takahashi, Ryohei" <r(dot)takahashi_2(at)jp(dot)fujitsu(dot)com>
To: "Matsumura, Ryo" <matsumura(dot)ryo(at)jp(dot)fujitsu(dot)com>, 'Michael Meskes' <meskes(at)postgresql(dot)org>, "'pgsql-hackers(at)postgresql(dot)org'" <pgsql-hackers(at)postgresql(dot)org>
Subject: RE: SQL statement PREPARE does not work in ECPG
Date: 2019-02-26 02:45:58
Message-ID: EE586BE92A4AFB45B03310C2A0C0565D6D398B2E@G01JPEXMBKW03
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi Matsumura-san,

Thank you for your explaining.

> An important point of the route is that it calls PQprepare() and PQprepare()
> needs type-Oid list. (Idea-1) If we fix for Prepare statement with AS clause and
> with parameter list to walk through the route, preprocessor must parse the parameter list and
> preprocessor or ecpglib must make type-Oid list. I think it's difficult.
> Especially, I wonder if it can treat user defined type and complex structure type.

I agree.
In the case of standard types, ECPG can get oids from pg_type.h.
However, in the case of user defined types, ECPG needs to access pg_type table and it is overhead.

Therefore, the second idea seems better.

By the way, should we support prepare statement like following?
(I think yes.)

EXEC SQL PREPARE test_prep (int) AS SELECT id from test_table where id = :ID or id =$1;

Current ECPG produces following code.

ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "prepare \"test_prep\" ( int ) as \" select id from test_table where id = $1 or id = $1 \"",

In this case, both ":ID" and "$1" in the original statement are converted to "$1" and ECPGdo() cannot distinguish them.
Therefore, ECPG should produce different code.

For example,
- ECPG convert ":ID" to "$1" and "$1" in the original statement to "$$1"
- next_insert() do not check "$$1"
- ECPGdo() reconvert "$$1" to "$1"

Ryohei Takahashi

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2019-02-26 02:53:26 Re: POC: converting Lists into arrays
Previous Message Andrew Gierth 2019-02-26 02:39:42 Re: JIT on FreeBSD ARMv7