pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
libpq - PGexecPrepared - INT4OID binary parameter mode not working
2+ messages / 2 participants
[nested] [flat]

* libpq - PGexecPrepared - INT4OID binary parameter mode not working
@ 2007-02-02 13:11 jp.duval@up-comp.com
  2007-02-06 05:14 ` Re: libpq - PGexecPrepared - INT4OID binary parameter mode not working Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: jp.duval@up-comp.com @ 2007-02-02 13:11 UTC (permalink / raw)
  To: pgsql-interfaces

Good morning.

Could someone help me on understanding why PQexecParams is not working properly
while using parameters in binary mode?

I use PostgreSQL 8.1 on Windows XP. The database server and the client are on
the same computer. Enclosed:
1) Table used.
2) An example using text mode that is working.
3) The same example using binary mode that is not working.

Is it possible to trave the behavior of libpq?

Jean-Pierre DUVAL, Product Manager - jp.duval@up-comp.com - www.up-comp.com

* * *

TABLE scott.emp
/*************/
CREATE TABLE scott.emp
   (
   empno int4 NOT NULL,
   ename varchar(10) NOT NULL,
   job varchar(9),
   mgr int4,
   hiredate date,
   sal float8,
   comm float8,
   deptno int4 NOT NULL
   ) WITHOUT OIDS;

* * *

long Working(PGconn *HandleConnexion)
/***********************************/
{
Oid TableParametresTypesTransmis[]={INT4OID};
char *Valeur="10";
char *TableParametresValeursTransmis[]={(char *)Valeur};
int TableParametresTaillesTransmis[]={2};
int TableParametresFormatsTransmis[]={0};

PGresult *Handle;
long NbEnregistrements;

Handle=PQexecParams(HandleConnexion,
   "SELECT ename, hiredate, empno, sal FROM scott.emp WHERE deptno=$1::int4",
  
1,TableParametresTypesTransmis,TableParametresValeursTransmis,TableParametresTaillesTransmis,TableParametresFormatsTransmis,1);
if (!Handle)
   return(0);
switch (PQresultStatus(Handle))
   {
   case PGRES_COMMAND_OK :
   case PGRES_TUPLES_OK :
   case PGRES_COPY_OUT :
   case PGRES_COPY_IN :
   case PGRES_NONFATAL_ERROR :
      break;

   case PGRES_EMPTY_QUERY :
      LireNbEnregistrementsAffectes=0;
      return(1);
      break;

   default :
      break;
   }
NbEnregistrements=(long)PQntuples(Handle);
/***************************************/
/* NbEnregistrements == 3, what is Ok. */
/***************************************/
return(NbEnregistrements);
}

long NotWorking(PGconn *HandleConnexion)
/**************************************/
{
Oid TableParametresTypesTransmis[]={INT4OID};
int Valeur=10;
char *TableParametresValeursTransmis[]={(char *)&Valeur};
int TableParametresTaillesTransmis[]={sizeof(int)};
int TableParametresFormatsTransmis[]={1};

PGresult *Handle;
long NbEnregistrements;

Handle=PQexecParams(HandleConnexion,
   "SELECT ename, hiredate, empno, sal FROM scott.emp WHERE deptno=$1::int4",
  
1,TableParametresTypesTransmis,TableParametresValeursTransmis,TableParametresTaillesTransmis,TableParametresFormatsTransmis,1);
if (!Handle)
   return(0);
switch (PQresultStatus(Handle))
   {
   case PGRES_COMMAND_OK :
   case PGRES_TUPLES_OK :
   case PGRES_COPY_OUT :
   case PGRES_COPY_IN :
   case PGRES_NONFATAL_ERROR :
      break;

   case PGRES_EMPTY_QUERY :
      LireNbEnregistrementsAffectes=0;
      return(1);
      break;

   default :
      break;
   }
NbEnregistrements=(long)PQntuples(Handle);
/******************************************/
/* NbEnregistrements == 0, what is FALSE. */
/******************************************/
return(NbEnregistrements);
}





^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: libpq - PGexecPrepared - INT4OID binary parameter mode not working
  2007-02-02 13:11 libpq - PGexecPrepared - INT4OID binary parameter mode not working jp.duval@up-comp.com
@ 2007-02-06 05:14 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2007-02-06 05:14 UTC (permalink / raw)
  To: jp.duval@up-comp.com; +Cc: pgsql-interfaces

jp.duval@up-comp.com writes:
> Could someone help me on understanding why PQexecParams is not working properly
> while using parameters in binary mode?

I think you have forgotten to convert the values to network byte order.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2007-02-06 05:14 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-02-02 13:11 libpq - PGexecPrepared - INT4OID binary parameter mode not working jp.duval@up-comp.com
2007-02-06 05:14 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox