Subject: Bug in p_creat

From: [email-masked] (Siu Wah Lau)
Date: Mon, 7 Jun 93 16:50:38 -0700

Hi Everyone,

p_creat crashes at the middle when my program calls it.
I have set the variable "PQtracep" to 1 so that I can see
the execution steps.

The trace of the execution of my program is as follows:

The query sent to the backend: begin
The Identifier is: C
The Transaction Id is: 0
Query command: BEGIN
The Identifier is: ?
The Transaction Id is: 0
RESET CALLED FROM CASE G
Protocol Error, bad form, got '?'
Error: Unexpected identifier: ?

Could anyone help to correct the bug in p_creat?

Thank you.

Clarence.

The following is my program source:

--------------------------------- cut here ----------------------------
#include <stdio.h>
#include "tmp/c.h"
#include "tmp/libpq-fe.h"
#include "tmp/libpq-fs.h"
#include "catalog/pg_lobj.h"

extern int PQtracep;
main()
{
int	inv_fd, fd;
char	*res;
char buf[1024];
int nbytes;
int tmp;

	PQtracep = 1;

	PQsetdb("lau");
	res = PQexec ("begin");
	if (*res == 'E')
	{
		printf("error in PQexec\n"); exit(1);
	}

	fd = open ("/etc/hosts", O_RDONLY, 0666);
	if (fd < 0) 
	{
		perror("/etc/hosts");
		printf("error in open\n"); exit(1);
	}

	inv_fd = p_creat("/inv_file", INV_READ|INV_WRITE, Inversion);
	fprintf(stderr, "complete\n");
	if (inv_fd < 0) 
	{
		fprintf(stderr, "error in p_open\n");
		printf("error in p_open\n"); exit(1);
	}

	while ((nbytes = read(fd, buf, 1024)) > 0)
	{
		tmp = p_write(inv_fd, buf, nbytes);
		if (tmp < nbytes)
		{
			printf("error in writing\n"); exit(1);
		}
	}
	close(fd);
	p_close(inv_fd);

	res = PQexec("end");
	if (*res == 'E')
	{
		printf("error in PQexec\n"); exit(1);
	}

	PQfinish();
}