Subject: libpq arguments

From: M92 <[email-masked]>
Date: Wed, 23 Jun 93 07:27:00 -0700

I'm using the libpq commands to issue from a c program a postquel query to the
postgres backend.

The difficulties occur when I try to use arguments, the standard c method for 
arguments use doesn't seem to work when the argument reference is inside the
postquel statement ie :

PQexec ("retrieve portal eportal (OBJECT.source) where OBJECT.name = \"%s\"", av[2]); 

Does anybody know how to get around this problem ?
Do I have to define a postquel function and then issue a function call using the
PQfn command ? - if so will ssomeone please explain how to operate this command.

I've include th whole c program below.

Thanks, Paul.
 
#include <sys/file.h>
#include <stdio.h>
#include "tmp/libpq.h"

void main(ac,av)
   int ac;
   char *av[];

{
	int i, j, k, g, n, m, t;
	PortalBuffer *p;
	char pnames[MAXPORTALS][portal_name_length];

        if ( ac!= 3 ) {
	  printf ("usage: %s database-name object-name\n", av[0]);
	  exit(1);
	}

	PQsetdb (av[1]);

	PQexec ("begin");
	PQexec ("retrieve portal eportal (OBJECT.source) where OBJECT.name = \"%s\"", av[2]);
	PQexec ("fetch all in eportal");
	printf ("retrieve portal eportal (OBJECT.source) where OBJECT.name = \"%s\"\n", av[2]);
	printf ("fetch all in eportal\n"); 

	p = PQparray ("eportal");
	g = PQngroups (p);
	t = 0;

	for (k = 0; k < g; k++) {
		printf ("\nA new instance group : \n");
		n = PQntuplesGroup (p, k);
		m = PQnfieldsGroup (p, k);

		for (i = 0; i < m; i++)
		printf ("%-20s", PQfnameGroup (p, k, i));
		printf ("\n");

		for (i = 0; i < n; i++) {
			for (j = 0; j < m; j++)
				printf ("%-20s", PQgetvalue (p, t+i , j));
				printf ("\n");
		}
		t += n;
	}
	PQexec ("close eportal");

	PQexec ("end");

	PQfinish ();
}

---

From: Wolf Guddat <[email-masked]>
Date: Fri, 25 Jun 93 9:59:12 MESZ

Hi Paul!

Refer to the Postgres-Reference-Manual pp.114
There the function is defined as
char *PQexec (char *)

Try somesthing like this: