From: Michael Vodep <mvodep@gmx.net>
To: pgsql-interfaces@postgresql.org
Subject: libpq(Win32) & BLOBs -> lo_write
Date: Sun, 26 Oct 2003 17:45:07 +0100 (MET)
Message-ID: <30627.1067186707@www61.gmx.net> (raw)
Hi!
I used following tuturial for inserting a BLOB.
http://www.postgresql.org/docs/7.3/interactive/lo-libpq.html
Now i tried to use the same in MFC
void CWordChildFrame::OnSaveRtf()
{
//BINARY LARGE OBJECT
PQexec(conn,"BEGIN");
Oid lobjId;
lobjId = importFile(conn,"C:\\myfile.rtf");
PGresult* res;
CString str;
str.Format("INSERT INTO tbldata (data) VALUES(%i) WHERE
blobid=0;",lobjId);
res = PQexec(conn,str);
PQexec(conn,"END");
}
Oid CWordChildFrame::importFile(PGconn *conn, char *filename)
{
Oid lobjId;
int lobj_fd;
char buf[BUFSIZE];
DWORD dwRead;
int nbytes,tmp;
int fd;
CFile cfile;
CFileException ex;
if(!cfile.Open(filename, CFile::modeRead, &ex)) {
TCHAR szError[1024];
ex.GetErrorMessage(szError, 1024);
}
else {
lobjId = lo_creat(conn, INV_READ | INV_WRITE);
if (lobjId == 0){
AfxMessageBox("BLOB kann nicht erstellt werden\n");
}
lobj_fd = lo_open(conn, lobjId, INV_WRITE);
do
{
dwRead = cfile.Read(buf, BUFSIZE);
tmp = lo_write(conn, lobj_fd, buf, nbytes);
if (tmp < nbytes)
AfxMessageBox("Lesefehler\n");
}
while(dwRead > 0);
(void)lo_close(conn, lobj_fd);
return lobjId;
}
}
I ahve got no errors - but nothing happens in the DB
What have i done wrong?
Thanks Michael
--
NEU FÜR ALLE - GMX MediaCenter - für Fotos, Musik, Dateien...
Fotoalbum, File Sharing, MMS, Multimedia-Gruß, GMX FotoService
Jetzt kostenlos anmelden unter http://www.gmx.net
+++ GMX - die erste Adresse für Mail, Message, More! +++
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-interfaces@postgresql.org
Cc: mvodep@gmx.net
Subject: Re: libpq(Win32) & BLOBs -> lo_write
In-Reply-To: <30627.1067186707@www61.gmx.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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