Subject: p_write

From: [email-masked] (Siu Wah Lau)
Date: Wed, 9 Jun 93 17:22:19 -0700

Hi Everyone,

My program calls p_write to write 4 bytes of data.
p_write fails to perform the write and gives the following messages:

The query sent to the backend: begin
The Identifier is: C
The Transaction Id is: 0
Query command: BEGIN
Error: WARN:Jun  9 17:21:17:Cannot initialize non-empty btree Xinx27552
complete
error in p_open
error in p_open

Could anyone fix the bug?

Clarence.

The following is my program:

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

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

	PQtrace();
	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);
	if (inv_fd < 0) 
	{
		fprintf(stderr, "error in p_open\n");
		printf("error in p_open\n"); exit(1);
	}

	while ((nbytes = read(fd, buf, 4)) > 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();
}