lo_write and lo_import does not work!

From: Miguel García <rocho08(at)yahoo(dot)es>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: lo_write and lo_import does not work!
Date: 2007-04-18 13:34:40
Message-ID: 471146.38834.qm@web26607.mail.ukl.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

Hello,

I have a little trouble using large objects with libpq an postgresql 8.2 in windows xp professional SP2.

I want to save and load large objects from/to database, but its fails.

If i try to use the lo_import() function

#define FILE_IN "d:/question-icon.png"
Oid file_oid = lo_import (conn, FILE_IN);

file_oid always have 0 value, nevertheless the large object has been created in table
pg_largeobject, but has no data.

If i try to create the large object by hand, read the file from disk, and then write the binary data
to the large object, the call to lo_write() always fail (always returns -1):

ifstream is;
is.open (FILE_IN, ios::binary );

// get length of file:
is.seekg (0, ios::end);
length = is.tellg();
is.seekg (0, ios::beg);

// allocate memory:
buffer = new char [length];

// read data as a block:
is.read (buffer,length);
is.close();

/*
* create the large object
*/
lobjId = lo_creat(conn, INV_WRITE);
if (lobjId == 0) {
fprintf(stderr, "no se pudo crear el objeto grande\n");
exit_nicely (conn);
}

lobj_fd = lo_open(conn, lobjId, INV_WRITE);

/*
* Write the content of the file to the large object
*/
tmp = lo_write(conn, lobj_fd, buffer, length);
if (tmp < length) {
fprintf(stderr, "error al escribir el objeto grande: %d bytes escritos\n", tmp);
exit_nicely (conn);
}

In this case, the call to lo_write() does not work, but i can see the large object created in table
pg_largeobject.

Any Idea?


____________________________________________________________________________________
LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y móviles desde 1 céntimo por minuto.
http://es.voice.yahoo.com

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Alvaro Herrera 2007-04-18 14:02:47 Re: lo_write and lo_import does not work!
Previous Message Alvaro Herrera 2007-04-17 13:07:04 Re: Implementing Frontend/Backend Protocol