home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 32 / IOPROG_32.ISO / SOFT / SqlEval7 / devtools / samples / ODBC / mfcperf / soset.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-20  |  2.9 KB  |  94 lines

  1. // SlowOrdersSet.cpp : implementation file
  2. //
  3. // This file is part of Microsoft SQL Server online documentation.
  4. // Copyright (C) 1992-1997 Microsoft Corporation. All rights reserved.
  5. //
  6. // This source code is an intended supplement to the Microsoft SQL
  7. // Server online references and related electronic documentation.
  8. #include "stdafx.h"
  9. #include "MFCPerf.h"
  10. #include "SOSet.h"
  11.  
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CSlowOrdersSet
  20. IMPLEMENT_DYNAMIC(CSlowOrdersSet, CRecordset)
  21.  
  22. CSlowOrdersSet::CSlowOrdersSet(CDatabase* pdb)
  23.     : CRecordset(pdb)
  24.     {
  25.     //{{AFX_FIELD_INIT(CSlowOrdersSet)
  26.     m_OrderID = 0;
  27.     m_nFields = 4;
  28.     //}}AFX_FIELD_INIT
  29.     }
  30.  
  31. CString CSlowOrdersSet::GetDefaultConnect()
  32.     {
  33.     return _T("");
  34.     }
  35.  
  36. CString CSlowOrdersSet::GetDefaultSQL()
  37.     {
  38.     return _T("[dbo].[Orders]");
  39.  
  40. //  Replacing the default SQL string with one of your own creation can often result
  41. //   in reducing the number of bytes sent to the server, for example:
  42. //    return _T("SELECT OrderID, OrderDate, RequiredDate, ShippedDate FROM Orders");
  43.     }
  44.  
  45. void CSlowOrdersSet::DoFieldExchange(CFieldExchange* pFX)
  46.     {
  47.     //{{AFX_FIELD_MAP(CSlowOrdersSet)
  48.     pFX->SetFieldType(CFieldExchange::outputColumn);
  49.     RFX_Long(pFX, _T("[OrderID]"), m_OrderID);
  50.     RFX_Date(pFX, _T("[OrderDate]"), m_OrderDate);
  51.     RFX_Date(pFX, _T("[RequiredDate]"), m_RequiredDate);
  52.     RFX_Date(pFX, _T("[ShippedDate]"), m_ShippedDate);
  53.     //}}AFX_FIELD_MAP
  54.     }
  55.  
  56. /////////////////////////////////////////////////////////////////////////////
  57. // CSlowOrdersSet diagnostics
  58. #ifdef _DEBUG
  59. void CSlowOrdersSet::AssertValid() const
  60.     {
  61.     CRecordset::AssertValid();
  62.     }
  63.  
  64. void CSlowOrdersSet::Dump(CDumpContext& dc) const
  65.     {
  66.     CRecordset::Dump(dc);
  67.     }
  68. #endif //_DEBUG
  69.  
  70. /*
  71. When using MFC with SQL Server, you should almost always override the Open
  72.  member function. By default, the MFC ODBC CRecordset asks for a scrollable,
  73.  updatable STATIC cursor. STATIC cursors are not updatable on SQL Server.
  74.  Therefore, statement preparation fails on the statement. The MFC CRecordset
  75.  will ask for an updatable cursor twice, before downgrading cursor
  76.  concurrency to read-only.
  77.  
  78. The effect can be seen in this example by using class wizard to add the code
  79.  below to both detail recordsets, and then running the performance test menu
  80.  item.
  81.  
  82. Server roundtrips will drop from 453 to 140. Bytes sent should drop by
  83.  roughly 2/3, and bytes received should more closely match that for the "fast"
  84.  method.
  85.  
  86. Rule: Know what type of behavior you need from your recordset, and then
  87.  use the Open member function to enforce that behavior.
  88.  
  89. BOOL CSlowOrdersSet::Open(UINT nOpenType, LPCTSTR lpszSql, DWORD dwOptions) 
  90.     {
  91.     return CRecordset::Open(CRecordset::forwardOnly, lpszSql, dwOptions);
  92.     }
  93. */
  94.