Skip site navigation (1) Skip section navigation (2)

libpq(Win32) & BLOBs -> lo_write

From: "Michael Vodep" <mvodep(at)gmx(dot)net>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: libpq(Win32) & BLOBs -> lo_write
Date: 2003-10-26 16:45:07
Message-ID: 30627.1067186707@www61.gmx.net (view raw or flat)
Thread:
Lists: pgsql-interfaces
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! +++


pgsql-interfaces by date

Next:From: creidDate: 2003-10-26 23:08:49
Subject: LIBPQ Question
Previous:From: Michael MeskesDate: 2003-10-26 09:51:07
Subject: Re: [BUGS] ECPG and NULL indicators

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group