Re: libpq: What can and cannot be bound? How to know?

From: Dominique Devienne <ddevienne(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: libpq: What can and cannot be bound? How to know?
Date: 2023-06-21 13:09:51
Message-ID: CAFCRh--VE_6H_gDX-hrN3T13JC4ADD3u0Z4H1J8yS4EM87TkSg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Jun 21, 2023 at 1:52 PM Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
wrote:

> On Wed, 2023-06-21 at 11:00 +0200, Dominique Devienne wrote:
> > [...] obvious way to know what can and cannot be bound, just from the
> doc?
>
> This is not adequately documented.

Bummer.

> The documentation for PREPARE says:
>

Note that I'm not even preparing in this case, but using PQexecParams()
instead.
So I'm unlikely to look at the PREPARE doc, but the one from the COMMAND
I'm actually using, i.e. NOTIFY in my example.

> so NOTIFY is not supported.

Bummer again.

So I must PQescapeIdentifier() and PQescapeLiteral() to have an iron-clad
NOTIFY,
as the 2nd pseudo-code above showed then. Thanks for confirming Laurenz.

> However, you need some inside knowledge to know
> that what you are running is an "unnamed prepared statement" and that the
> limitation
> stated in PREPARE applies.
>

I don't know what shape or form this could be specified in the doc.
Maybe specific and consistent typography for each "argument" kind,
like names, non-bind-able literals, bind-able literals? Just thinking aloud.
With a link in all commands to a "central" page about SQL Injection and
binding and format(), etc... maybe?

I do find it strange, from the user perspective, not to be able to bind the
NOTIFY's payload text message.
Or be able to bind the password in a CREATE USER. (Yes, I know
about PQencryptPasswordConn()).
I'm sure there are good technical reason. But from the outside, it is
surprising and a bit inconsistent.

My $0.02. --DD

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2023-06-21 14:20:09 Re: libpq: What can and cannot be bound? How to know?
Previous Message Jelte Fennema 2023-06-21 13:08:19 Re: Support logical replication of DDLs