overwriting large objects bug?

Started by St�phane Popinetalmost 27 years ago2 messagesgeneral
Jump to latest
#1St�phane Popinet
popinet@lmm.jussieu.fr

Hi,

I have some problems when trying to overwrite large objects (I use
postgres 6.3.2-10). Apparently, everything looks allright when
overwriting existing data but it fails when trying to write after the
end of the existing large object.

Before describing in more detail what happens, I'd like to ask to
questions:

- is that a known problem with large objects?
_ is there a function which allows to import a file in an already
existing large object (i.e. overwriting its contents)? (from what I saw
in libpq-fe.h probably not).

Actually the problem looks a bit more complex than what described above.
I use the function overwrite() given below.

Let's take an example to make the problem clearer

Given two files f1 and f2

f1 contains "abcdefghijklmnop"
f2 contains "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

a program looking like

opening connection ...

lobjid = lo_import(conn, "f1");
overwrite (conn, lobjid, "f2");
lo_export (conn, lobjid, "f3");

closing connection ...

works fine and f3 contains the same thing as f2, but if I divide this
single program into three separate programs looking like

program1: opening connection ...

lobjid = lo_import(conn, "f1");
printf("%d\n", lobjid);

closing connection ...

program2: opening connection ...

overwrite(conn, atoi(argv[1]), "f2");

closing connection ...

program3: opening connection ...

lo_export(conn, atoi(argv[1]), "f3");

closing connection ...

and runs the script

#!/bin/bash
id=`program1`
program2 $id
program3 $id

then f3 contains "abcdefghijklmnop\nRSTUVWXYZ".

Everything works fine if f2 is shorter or equal to f1

f1="abcdefghijklmnop", f2="ABCDEFGHIJKLMNOP" then
f3="ABCDEFGHIJKLMNOP"

Any idea to what is wrong? Am I wrong or is there a bug?

Thanks a lot

St�phane

--------------------------------------------------------------------------

int overwrite (PGconn * conn,
Oid lobjId,
const char * filename)
{
int lobj_fd;
char buf[BUFSIZE];
int nbytes;
int fd;
int status = -1;

lobj_fd = lo_open(conn, lobjId, INV_WRITE);
if (lobj_fd >= 0) {
if (lo_lseek(conn, lobj_fd, 0, SEEK_SET) >= 0) {
fd = open(filename, O_RDONLY, 0666);
if (fd >= 0) {
int n, nwritten;
status = 0;
while ((nbytes = read(fd, buf, BUFSIZE)) > 0) {
nwritten = 0;
while (nbytes - nwritten > 0) {
n = lo_write(conn, lobj_fd, buf + nwritten, nbytes - nwritten);
nwritten += n;
}
}
close(fd);
}
}
lo_close(conn, lobj_fd);
}
return status;
}

#2Bruce Momjian
bruce@momjian.us
In reply to: St�phane Popinet (#1)
Re: [GENERAL] overwriting large objects bug?

[Charset iso-8859-1 unsupported, filtering to ASCII...]

Hi,

I have some problems when trying to overwrite large objects (I use
postgres 6.3.2-10). Apparently, everything looks allright when
overwriting existing data but it fails when trying to write after the
end of the existing large object.

Before describing in more detail what happens, I'd like to ask to
questions:

- is that a known problem with large objects?
_ is there a function which allows to import a file in an already
existing large object (i.e. overwriting its contents)? (from what I saw
in libpq-fe.h probably not).

Known problem. Fixed in 6.5 beta. 6.5 final is due June 1.

-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026