specifying multiple result format codes with libpq

From: Abhijit Menon-Sen <ams(at)wiw(dot)org>
To: pgsql-hackers(at)postgresql(dot)org
Subject: specifying multiple result format codes with libpq
Date: 2004-06-18 15:02:45
Message-ID: 20040618203245.A13980@lustre.dyn.wiw.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

The documentation for PQexecPrepared says:

(There is not currently a provision to obtain different result
columns in different formats, although that is possible in the
underlying protocol.)

Would anyone be interested in a patch to allow this?

I could, for example, change PQsendQueryGuts to do something like:

static int PQsendQueryGuts( PGconn *conn,
const char *command,
const char *stmtName,
int nParams,
const Oid *paramTypes,
const char *const *paramValues,
const int *paramLengths,
const int *paramFormats,
int resultFormat,
... ) /* Add this last argument. */
{
...

if ( resultFormat == -1 ) { /* or == nParams, perhaps? */
va_list args;
const int *resultFormats;

va_start( args, resultFormat );
resultFormats = va_arg( args, const int * );
va_end( args );

if ( pqPutInt( nParams, 2, conn ) < 0 )
goto sendFailed;
for ( i = 0; i < nParams; i++ )
if ( pqPutInt( resultFormats[i], 2, conn ) < 0 )
goto sendFailed;
}
/* This is what libpq does already. */
else if ( pqPutInt( 1, 2, conn ) < 0 ||
pqPutInt( resultFormat, 2, conn ) )
goto sendFailed;

...
}

And then teach the other API functions (PQexecParams, PQsendQueryParams,
PQsendQueryPrepared) to accept and pass on the extra ... argument. That
wouldn't break existing code, and new users could set resultFormat to
invoke the new behaviour. It seems a bit ugly, but on the other hand,
it doesn't seem worthwhile to add a new interface for this behaviour.

Thoughts?

-- ams

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2004-06-18 15:03:50 Re: SPI equivalent for libpq PQftable & PQFtablecolumn
Previous Message Larry Rosenman 2004-06-18 14:52:38 Re: SCO embraces MySQL