CRecordSet in Bulk mode how to Add,Delete,Update 
Author Message
 CRecordSet in Bulk mode how to Add,Delete,Update

Hi  Everbody:

    Someone can give me suggetion. I want to use CRecordSet
in bulk mode and I had seen the sample in MFC. The sample that only
show read data from table but it doesn't show how to ADD,DELETE,
UPDATE. I am not clear to use ODBC API call . Thanks.

Eric Hu



Mon, 20 Nov 2000 03:00:00 GMT  
 CRecordSet in Bulk mode how to Add,Delete,Update

Dear Caco:

Quote:
> Hi,

> CRecordset doesn't allow to use AddNew(), Edit(), Delte(), and Update(),
> when you use it in bulk mode....

> Only the way to update in bulk mode is to write yourown code with
> SQLSetPos (ODBC API).

 Yes, I know but how to write it .
  Maybe has other relation API called before SQLSetPos that to accomplish
need.
Quote:

> --- Caco



Mon, 20 Nov 2000 03:00:00 GMT  
 CRecordSet in Bulk mode how to Add,Delete,Update

Hi,

CRecordset doesn't allow to use AddNew(), Edit(), Delte(), and Update(),
when you use it in bulk mode....

Only the way to update in bulk mode is to write yourown code with
SQLSetPos (ODBC API).

--- Caco

Eric Hu wrote in article

Quote:
> Hi  Everbody:

>     Someone can give me suggetion. I want to use CRecordSet
> in bulk mode and I had seen the sample in MFC. The sample that only
> show read data from table but it doesn't show how to ADD,DELETE,
> UPDATE. I am not clear to use ODBC API call . Thanks.

> Eric Hu



Tue, 21 Nov 2000 03:00:00 GMT  
 CRecordSet in Bulk mode how to Add,Delete,Update

Hi Group! and
Dear Eric,

a Sample program "DBFETCH" will  help you.
It is included in VC++.
(I'm using VC++ 5.0 Enterprise Edition.)

Eric Hu wrote in article

Quote:
> > Only the way to update in bulk mode is to write yourown code with
> > SQLSetPos (ODBC API).
>  Yes, I know but how to write it .

Oh, Excuse me...

Quote:
>   Maybe has other relation API called before SQLSetPos that to accomplish
> need.

> > --- Caco

anyway, I'll pick up some parts of it's code for you. Please see below.

--- Caco.

// CDynamicBulkSet recordset

class CDynamicBulkSet : public CBulkRecordsetMod
{
public:
        CDynamicBulkSet(CDatabase* pDatabase = NULL);
        DECLARE_DYNAMIC(CDynamicBulkSet)

        virtual void Close();

// Attributes
        int m_nAllocatedFields;
        void** m_ppvData;        // allocate dynamically to nColumns later
        void** m_ppvLengths; // allocate dynamically to nColumns later

// Overridables
        virtual void DoBulkFieldExchange(CFieldExchange* pFX);
        virtual void CheckRowsetError(RETCODE nRetCode);

Quote:
};

CBulkRecordsetMod::CBulkRecordsetMod(CDatabase* pdb)
        : CRecordset(pdb)
{
        //{{AFX_FIELD_INIT(CBulkRecordsetMod)
        //}}AFX_FIELD_INIT
        m_nDefaultType = dynaset;

Quote:
}

BOOL CBulkRecordsetMod::Open(UINT nOpenType,
        LPCTSTR lpszSQL, DWORD dwOptions)
{
        ASSERT(dwOptions & useMultiRowFetch);
        return CRecordset::Open(nOpenType, lpszSQL, dwOptions);

Quote:
}

BOOL CBulkRecordsetMod::RowsetUpdate(WORD wRow, WORD wLockType)
{
        ASSERT(wRow >= 0 && wRow <= GetRowsetSize());

        RETCODE nRetCode;
        AFX_ODBC_CALL(::SQLSetPos(m_hstmt, wRow, SQL_UPDATE, wLockType));

        return ValidateMod(wRow, SQL_ROW_UPDATED);

Quote:
}

BOOL CBulkRecordsetMod::RowsetAdd(WORD wRow, WORD wLockType)
{
        // User may allocate an extra row buffer for the Add
        // (if user adds more than 1, must override)
        ASSERT(wRow >= 0 && wRow <= GetRowsetSize() + 1);

        RETCODE nRetCode;
        AFX_ODBC_CALL(::SQLSetPos(m_hstmt, wRow, SQL_ADD, wLockType));

        return ValidateMod(wRow, SQL_ROW_ADDED);

Quote:
}

BOOL CBulkRecordsetMod::RowsetDelete(WORD wRow, WORD wLockType)
{
        ASSERT(wRow >= 0 && wRow <= GetRowsetSize());

        RETCODE nRetCode;
        AFX_ODBC_CALL(::SQLSetPos(m_hstmt, wRow, SQL_DELETE, wLockType));

        return ValidateMod(wRow, SQL_ROW_DELETED);

Quote:
}

BOOL CBulkRecordsetMod::ValidateMod(WORD wRow, WORD wExpectedStatus)
{
        BOOL bReturn = TRUE;

        if (wRow != 0)
                bReturn = GetRowStatus(wRow) == wExpectedStatus;
        else
        {
                for (WORD wNum = 1; wNum <= GetRowsetSize(); wNum++)
                {
                        // If any row status not expected, then validate fails
                        if (GetRowStatus(wNum) != wExpectedStatus)
                                bReturn = FALSE;
                }
        }

        return bReturn;

Quote:
}

//  end


Tue, 21 Nov 2000 03:00:00 GMT  
 CRecordSet in Bulk mode how to Add,Delete,Update

Hi,

-- Addition ---

Please use the code below instead of CDynamicBulkSet class.
Excuse me.

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

// Operations
public:
        virtual BOOL Open(UINT nOpenType = AFX_DB_USE_DEFAULT_TYPE,
                LPCTSTR lpszSQL = NULL, DWORD dwOptions = useMultiRowFetch);

        virtual BOOL RowsetUpdate(WORD wRow, WORD wLockType = SQL_LOCK_NO_CHANGE);
        virtual BOOL RowsetAdd(WORD wRow, WORD wLockType = SQL_LOCK_NO_CHANGE);
        virtual BOOL RowsetDelete(WORD wRow, WORD wLockType = SQL_LOCK_NO_CHANGE);

// Implemenation
public:
        BOOL ValidateMod(WORD wRow, WORD wExpectedStatus);

Quote:
};



Tue, 21 Nov 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. CRecordSet in Bulk mode how to Add,Delete,Update

2. Bulk Fetching and AddNew/Edit/Delete/Update

3. Add/Delete while using Bulk fetch

4. Need VC++6 Example to Update, Delete, Add and Search on Access Data

5. Q: CRecordSet::Delete() doesn't really delete??

6. CRecordset bulk row fetch broken?

7. Leaky CRecordset::Bulk RFX help?

8. ODBC CRecordSet Bulk Fetching

9. CRecordset bulk read problem

10. CRecordset::Delete does not delete my record!

11. CRecordset Bulk Row Fetching

12. Using Bulk record fetching with CRecordset

 

 
Powered by phpBB® Forum Software