Hi!

It seems that postgres allows writing to a read-only blob opened like:

        fd = lo_open (cnc, oid, INV_READ);

I've attached a simple test case and the Makefile to build it.

I'm using postgresql 7.3.3 (7.3.3-1 is the debian package version).

Is that the intended behaviour or is it a bug?

-Gonzalo

P.S.: please, CC me as I'm not suscribed to this list. Thanks.

-- 
Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
http://www.gnome-db.org/~gonzalo/



#include <string.h>
#include <libpq-fe.h>
#include <libpq/libpq-fs.h>

static char *conn_string =
	"dbname=test user=gonzalo password=password hostaddr=127.0.0.1";

int
main ()
{
	PGconn *cnc;
	PGresult *res;
	int oid, fd;
	char *the_string = "The String";
	char *other_str = "            ";
	int written;
	int result = 0;

	cnc = PQconnectdb (conn_string);
	if (PQstatus (cnc) != CONNECTION_OK) {
		printf ("Error connecting: %s\n", PQerrorMessage (cnc));
		return -1;
	}

	res = PQexec (cnc, "begin");
	PQclear(res);

	oid = lo_creat (cnc, INV_READ | INV_WRITE); /* Don't care if only one is set */
	fd = lo_open (cnc, oid, INV_READ);
	if (fd < 0) {
		printf ("Error opening BLOB: %s\n", PQerrorMessage (cnc));
		return -1;
	}
	
	written = lo_write (cnc, fd, the_string, strlen (the_string));
	if (written >= 0) {
		printf ("ERROR: I was able to write %d bytes.\n", written);
		result = 1;
	} else {
		printf ("It worked! %s\n", PQerrorMessage (cnc));
	}

	lo_close (cnc, fd);
	lo_unlink (cnc, oid);

	res = PQexec (cnc, "end");
	PQclear (res);
	PQfinish (cnc);

	return result;
}

CC=gcc
CFLAGS = -g -I/usr/include/postgresql
LDFLAGS = -lpq

inversion-bug: inversion-bug.o

inversion-bug.o: inversion-bug.c

clean:;
	rm -f *.o inversion-bug *~

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faqs/FAQ.html

Reply via email to