Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

159 lines
4.2 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1997-1999, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // SimTable.h
  8. //
  9. // SYNOPSIS
  10. //
  11. // This file describes the class CSimpleTable
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 10/31/1997 Original version.
  16. // 02/09/1998 Reorganized some things to make is easier to extend.
  17. // Thierry Perraut
  18. //
  19. ///////////////////////////////////////////////////////////////////////////////
  20. #ifndef _SIMTABLE_H_
  21. #define _SIMTABLE_H_
  22. #include <atlbase.h>
  23. #include <oledb.h>
  24. #include <bitvec.h>
  25. struct DBBinding;
  26. ///////////////////////////////////////////////////////////////////////////////
  27. //
  28. // CLASS
  29. //
  30. // CSimpleTable
  31. //
  32. // DESCRIPTION
  33. //
  34. // This class provides a simple read-only wrapper for iterating through a
  35. // rowset and retrieving information. The interface is based on the ATL
  36. // CTable<> class. I kept all the function signatures the same, so the two
  37. // should be almost interchangeable. The main difference is that CTable<>
  38. // opens a table and retrieves a rowset, while CSimpleTable is handed a
  39. // rowset that was retrieved elsewhere.
  40. //
  41. ///////////////////////////////////////////////////////////////////////////////
  42. class CSimpleTable
  43. {
  44. public:
  45. CSimpleTable();
  46. ~CSimpleTable();
  47. HRESULT Attach(IRowset* pRowset);
  48. IRowset* Detach();
  49. HRESULT MoveFirst();
  50. HRESULT MoveNext();
  51. HRESULT Insert();
  52. HRESULT Delete();
  53. HRESULT SetData();
  54. void DiscardChanges()
  55. {
  56. dirty.reset();
  57. }
  58. DBORDINAL GetColumnCount() const
  59. {
  60. return numColumns;
  61. }
  62. DBCOLUMNFLAGS GetColumnFlags(DBORDINAL nOrdinal) const
  63. {
  64. return columnInfo[OrdinalToColumn(nOrdinal)].dwFlags;
  65. }
  66. LPCWSTR GetColumnName(DBORDINAL nOrdinal) const
  67. {
  68. return columnInfo[OrdinalToColumn(nOrdinal)].pwszName;
  69. }
  70. DBTYPE GetColumnType(DBORDINAL nOrdinal) const
  71. {
  72. return columnInfo[OrdinalToColumn(nOrdinal)].wType;
  73. }
  74. DBLENGTH GetLength(DBORDINAL nOrdinal) const;
  75. bool GetOrdinal(LPCWSTR szColumnName, DBORDINAL* pOrdinal) const;
  76. DBSTATUS GetStatus(DBORDINAL nOrdinal) const;
  77. const void* GetValue(DBORDINAL nOrdinal) const
  78. {
  79. return _GetDataPtr(nOrdinal);
  80. }
  81. template <class T>
  82. void SetValue(DBORDINAL nOrdinal, const T& t)
  83. {
  84. *(T*)_GetDataPtr(nOrdinal) = t;
  85. }
  86. void SetValue(DBORDINAL nOrdinal, PCSTR szValue)
  87. {
  88. strcpy((PSTR)_GetDataPtr(nOrdinal), szValue);
  89. }
  90. void SetValue(DBORDINAL nOrdinal, PSTR szValue)
  91. {
  92. strcpy((PSTR)_GetDataPtr(nOrdinal), szValue);
  93. }
  94. bool HasBookmark() const
  95. {
  96. return (numColumns > 0) && (columnInfo->iOrdinal == 0);
  97. }
  98. protected:
  99. enum { FETCH_QUANTUM = 256 }; // The number of rows fetched at a time.
  100. HRESULT CreateAccessorForWrite(HACCESSOR* phAccessor);
  101. void* _GetDataPtr(DBORDINAL nOrdinal);
  102. const void* _GetDataPtr(DBORDINAL nOrdinal) const
  103. {
  104. return buffer +
  105. (ULONG_PTR)columnInfo[OrdinalToColumn(nOrdinal)].pTypeInfo;
  106. }
  107. HRESULT ReleaseRows();
  108. DBORDINAL OrdinalToColumn(DBORDINAL nOrdinal) const
  109. {
  110. return nOrdinal -= columnInfo->iOrdinal;
  111. }
  112. // Various representations of the rowset being manipulated.
  113. CComPtr<IRowset> rowset;
  114. CComPtr<IAccessor> accessor;
  115. CComPtr<IRowsetChange> rowsetChange;
  116. DBORDINAL numColumns; // Number of columns in the table.
  117. DBCOLUMNINFO* columnInfo; // Column info.
  118. OLECHAR* stringsBuffer; // Buffer used by columnInfo.
  119. DBBinding* columnBinding; // Column bindings.
  120. HACCESSOR readAccess; // Handle for read accessor.
  121. PBYTE buffer; // Accessor buffer.
  122. DBLENGTH bufferLength; // Length of accessor buffer.
  123. HROW row[FETCH_QUANTUM]; // Array of row handles.
  124. DBCOUNTITEM numRows; // Number of rows in the row array.
  125. DBCOUNTITEM currentRow; // Current row being accessed.
  126. BitVector dirty; // Columns that have been modified.
  127. bool endOfRowset; // True if we've reached the end of the rowset.
  128. };
  129. #endif // _SIMTABLE_H_