specifying multiple result format codes with libpq - Mailing list pgsql-hackers

From Abhijit Menon-Sen
Subject specifying multiple result format codes with libpq
Date
Msg-id 20040618203245.A13980@lustre.dyn.wiw.org
Whole thread Raw
Responses Re: specifying multiple result format codes with libpq
List pgsql-hackers
The documentation for PQexecPrepared says:
   (There is not currently a provision to obtain different result   columns in different formats, although that is
possiblein 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,
constchar *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


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: SPI equivalent for libpq PQftable & PQFtablecolumn
Next
From: Tom Lane
Date:
Subject: Re: korean encoding, but sort order bad