CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 1999
    Posts
    6

    How to use CLongBinary

    Hi,

    We are trying to write a BLOB (LOB) column in a database via ODBC. In the RecordSet we have bound that column to a CLongBinary object but we have problems using it. After inserting a new record in the database, the field of that column appears always NULL.

    Does anyone know whats the problem?

    Thanks


  2. #2
    Join Date
    Apr 1999
    Posts
    38

    Re: How to use CLongBinary

    Hello,

    The addition of blob field to the database needs extra care to be taken. Actually, internally when a new records is being added the Fields are set to null and the dirty flag is set byt the following functions

    SetFieldNull()
    SetFieldStatusDirty()

    But for the blob field this is not done. So, you need to do it explicitly before the update statement.

    Are you able to copy the data to CLongBinary object, if not this also has to be done explicitly by copying the data into the CLongBinary objects.

    Hope this solves your problem
    bye


  3. #3
    Join Date
    Jun 1999
    Location
    GERMANY
    Posts
    6

    Re: How to use CLongBinary

    Don't worry!

    Try CByteArray, works fine!

    CByteArray d;
    for(int i=0; i<size;++i)
    d.SetAtGrow(i, ch[i]);

    ch - source of BLOB data with length=size



  4. #4
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: How to use CLongBinary

    Do you have any samples for me? Please do help on how to store image into database (VC++ 5.0)

    Regards,
    Ramkrishna Pawar

  5. #5
    Join Date
    Jun 1999
    Location
    GERMANY
    Posts
    6

    Re: How to use CLongBinary

    This examples for RDBS Interbase:
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    // quartzDlg.cpp : implementation file
    //

    #include "stdafx.h"
    #include "quartzDlg.h"

    void CQuartzDlg::OnStart()
    {
    register int i;
    int transact = FALSE, failed = FALSE;

    CDatabase dbase;

    try
    {
    if(! dbase.Open(NULL, FALSE, FALSE, "ODBC;DSN=quartz;USER=dbclient;"))
    return;
    }
    catch(CDBException *e)
    {
    e-&gt;ReportError();
    e-&gt;Delete();
    return;
    }

    if(dbase.CanTransact() == FALSE)
    {
    MessageBox("Á*ç* ä***ûõ *å ïîääåðæèâ*åò òð**ç*êöèè","Ïðåäóïðåæäå*èå",
    MB_ICONWARNING);
    transact = FALSE;
    }
    else
    {
    dbase.BeginTrans();
    transact = TRUE;
    }

    CRefer rec(&dbase);
    rec.m_strFilter = _T("TYPE1ID=-1");
    try
    {
    if(! rec.Open(CRecordset::snapshot, _T("[REFER]"),
    CRecordset::executeDirect|CRecordset::appendOnly))
    return;
    }
    catch(CDBException *e)
    {
    e-&gt;ReportError();
    e-&gt;Delete();
    return;
    }


    char buf[1024];
    while(f.Read(buf, sizeof(buf)))
    {
    rec.AddNew();

    // Blob ------------------------------------------------------//
    for(i = 0; i &lt; sizeof(buf); ++i) //
    rec.m_SRC.SetAtGrow(i, (BYTE)(buf[i] & 0xff)); //
    //
    --------------------------------------------------------------//

    try
    {
    rec.Update();
    }
    catch(CDBException* e)
    {
    e-&gt;ReportError();
    e-&gt;Delete();
    }
    }

    ...

    rec.Close();
    dbase.Close();
    }


    //=========================================================================
    class CRefer : public CRecordset
    {
    public:
    CRefer(CDatabase* pDatabase = NULL);
    DECLARE_DYNAMIC(CRefer)

    // Field/Param Data
    //{{AFX_FIELD(CRefer, CRecordset)
    CByteArray m_SRC;
    //}}AFX_FIELD

    // Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CRefer)
    public:
    virtual CString GetDefaultSQL(); // Default SQL for Recordset
    virtual void DoFieldExchange(CFieldExchange* pFX); // RFX support
    //}}AFX_VIRTUAL
    };


    // Refer.cpp : implementation file
    //

    #include "stdafx.h"
    #include "Refer.h"

    /////////////////////////////////////////////////////////////////////////////
    // CRefer

    IMPLEMENT_DYNAMIC(CRefer, CRecordset)

    CRefer::CRefer(CDatabase* pdb)
    : CRecordset(pdb)
    {
    //{{AFX_FIELD_INIT(CRefer)
    m_nFields = 1;
    //}}AFX_FIELD_INIT
    m_nDefaultType = snapshot;
    }

    CString CRefer::GetDefaultSQL()
    {
    return _T("[REFER]");
    }

    void CRefer:oFieldExchange(CFieldExchange* pFX)
    {
    //{{AFX_FIELD_MAP(CRefer)
    pFX-&gt;SetFieldType(CFieldExchange:utputColumn);
    RFX_Binary(pFX, _T("[SRC]"), m_SRC, 1024);
    //}}AFX_FIELD_MAP
    }





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured