pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: jp.duval@up-comp.com
To: pgsql-interfaces@postgresql.org
Subject: libpq - PGexecPrepared - INT4OID binary parameter mode not working
Date: Fri,  2 Feb 2007 14:11:18 +0100
Message-ID: <1170421878.45c338769edfd@ssl0.ovh.net> (raw)

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);
}





view thread (2+ messages)  latest in thread

Message-ID: <1170421878.45c338769edfd@ssl0.ovh.net>
Permalink:  ../1170421878.45c338769edfd@ssl0.ovh.net/
Also on:    postgresql.org/message-id/1170421878.45c338769edfd@ssl0.ovh.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: jp.duval@up-comp.com
  Subject: Re: libpq - PGexecPrepared - INT4OID binary parameter mode not working
  In-Reply-To: <1170421878.45c338769edfd@ssl0.ovh.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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