pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedlo_write and lo_import does not work!
3+ messages / 2 participants
[nested] [flat]
* lo_write and lo_import does not work!
@ 2007-04-18 13:34 Miguel García <rocho08@yahoo.es>
0 siblings, 1 reply; 3+ messages in thread
From: Miguel García @ 2007-04-18 13:34 UTC (permalink / raw)
To: 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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: lo_write and lo_import does not work!
@ 2007-04-18 14:02 Alvaro Herrera <alvherre@commandprompt.com>
parent: Miguel García <rocho08@yahoo.es>
0 siblings, 0 replies; 3+ messages in thread
From: Alvaro Herrera @ 2007-04-18 14:02 UTC (permalink / raw)
To: Miguel García <rocho08@yahoo.es>; +Cc: pgsql-interfaces
Miguel García escribió:
> 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.
I think your problem is that you are not running the commands inside a
transaction. Large object IDs are closed at the end of the transaction
block, which is right after the lo_open unless you're calling BEGIN
first (or are not in autocommit mode, which is the default).
--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: lo_write and lo_import does not work!
@ 2007-04-18 14:21 Miguel García <rocho08@yahoo.es>
0 siblings, 0 replies; 3+ messages in thread
From: Miguel García @ 2007-04-18 14:21 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@commandprompt.com>; +Cc: pgsql-interfaces
It works!!
Thank you very much.
----- Mensaje original ----
De: Alvaro Herrera <alvherre@commandprompt.com>
Para: Miguel García <rocho08@yahoo.es>
CC: pgsql-interfaces@postgresql.org
Enviado: miércoles, 18 de abril, 2007 16:02:47
Asunto: Re: [INTERFACES] lo_write and lo_import does not work!
Miguel García escribió:
> 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.
I think your problem is that you are not running the commands inside a
transaction. Large object IDs are closed at the end of the transaction
block, which is right after the lo_open unless you're calling BEGIN
first (or are not in autocommit mode, which is the default).
--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
____________________________________________________________________________________
LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y móviles desde 1 céntimo por minuto.
http://es.voice.yahoo.com
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2007-04-18 14:21 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-04-18 13:34 lo_write and lo_import does not work! Miguel García <rocho08@yahoo.es>
2007-04-18 14:02 ` Alvaro Herrera <alvherre@commandprompt.com>
2007-04-18 14:21 Re: lo_write and lo_import does not work! Miguel García <rocho08@yahoo.es>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox