Source code of Windows XP (NT5)
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.

161 lines
4.1 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. template <>
  87. void SetValue(DBORDINAL nOrdinal, PCSTR szValue)
  88. {
  89. strcpy((PSTR)_GetDataPtr(nOrdinal), szValue);
  90. }
  91. template <>
  92. void SetValue(DBORDINAL nOrdinal, PSTR szValue)
  93. {
  94. strcpy((PSTR)_GetDataPtr(nOrdinal), szValue);
  95. }
  96. bool HasBookmark() const
  97. {
  98. return (numColumns > 0) && (columnInfo->iOrdinal == 0);
  99. }
  100. protected:
  101. enum { FETCH_QUANTUM = 256 }; // The number of rows fetched at a time.
  102. HRESULT CreateAccessorForWrite(HACCESSOR* phAccessor);
  103. void* _GetDataPtr(DBORDINAL nOrdinal);
  104. const void* _GetDataPtr(DBORDINAL nOrdinal) const
  105. {
  106. return buffer +
  107. (ULONG_PTR)columnInfo[OrdinalToColumn(nOrdinal)].pTypeInfo;
  108. }
  109. HRESULT ReleaseRows();
  110. DBORDINAL OrdinalToColumn(DBORDINAL nOrdinal) const
  111. {
  112. return nOrdinal -= columnInfo->iOrdinal;
  113. }
  114. // Various representations of the rowset being manipulated.
  115. CComPtr<IRowset> rowset;
  116. CComPtr<IAccessor> accessor;
  117. CComPtr<IRowsetChange> rowsetChange;
  118. DBORDINAL numColumns; // Number of columns in the table.
  119. DBCOLUMNINFO* columnInfo; // Column info.
  120. OLECHAR* stringsBuffer; // Buffer used by columnInfo.
  121. DBBinding* columnBinding; // Column bindings.
  122. HACCESSOR readAccess; // Handle for read accessor.
  123. PBYTE buffer; // Accessor buffer.
  124. DBLENGTH bufferLength; // Length of accessor buffer.
  125. HROW row[FETCH_QUANTUM]; // Array of row handles.
  126. DBCOUNTITEM numRows; // Number of rows in the row array.
  127. DBCOUNTITEM currentRow; // Current row being accessed.
  128. BitVector dirty; // Columns that have been modified.
  129. bool endOfRowset; // True if we've reached the end of the rowset.
  130. };
  131. #endif // _SIMTABLE_H_