Re: [INTERFACES] ExecCommandOk() return code always zero?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: blackw(at)sfu(dot)ca
Cc: pgsql-interfaces(at)postgreSQL(dot)org
Subject: Re: [INTERFACES] ExecCommandOk() return code always zero?
Date: 2000-02-03 01:36:22
Message-ID: 24369.949541782@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

Richard <blackw(at)sfu(dot)ca> writes:
> Why would ExecCommandOk() and ExecTuplesOk() be returning these
> consistent values? The docs indicate the ExecCommandOk() should be
> returning TRUE instead of FALSE, and ExecTuplesOk() should only be
> returning TRUE if there are tuples to be retreived.

Those docs are certainly wrong about ExecTuplesOk. ExecTuplesOk
should return TRUE if your query was valid, regardless of whether
any tuples were found. Otherwise, you cannot tell the difference
between a bogus query (a syntax error, for example) and a correct
query that returned zero tuples.

ExecCommandOk is supposed to be used for query types that are incapable
of ever returning tuples (INSERT or UPDATE for example). Perhaps it
shouldn't return FALSE if you give it a valid SELECT --- that's an
interesting philosophical question. The query is "valid" ... but on
the other hand, if the application used ExecCommandOk rather than
ExecTuplesOk, that implies that it's not expecting to get any tuples
back. So *in that context* you could argue that the query is the wrong
type of query. Similarly, it's not entirely clear what ExecTuplesOk
should do if you hand it an INSERT-type query ... but since that
strongly suggests that the application is badly confused, I think
raising an error isn't unreasonable.

In short, I think we've got a documentation bug here. Can you
suggest a revision that would have make it more clear to you?

regards, tom lane

In response to

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Kim Thye Chua 2000-02-03 08:03:31 problem installing pgsql_perl5 1.8.1
Previous Message Craig Orsinger 2000-02-03 01:28:07 Compiling C Language Functions On WinNT