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.

161 lines
4.2 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1997, 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. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #ifndef _SIMTABLE_H_
  20. #define _SIMTABLE_H_
  21. #include <atlbase.h>
  22. #include <oledb.h>
  23. #include <bitvec.h>
  24. struct DBBinding;
  25. ///////////////////////////////////////////////////////////////////////////////
  26. //
  27. // CLASS
  28. //
  29. // CSimpleTable
  30. //
  31. // DESCRIPTION
  32. //
  33. // This class provides a simple read-only wrapper for iterating through a
  34. // rowset and retrieving information. The interface is based on the ATL
  35. // CTable<> class. I kept all the function signatures the same, so the two
  36. // should be almost interchangeable. The main difference is that CTable<>
  37. // opens a table and retrieves a rowset, while CSimpleTable is handed a
  38. // rowset that was retrieved elsewhere.
  39. //
  40. ///////////////////////////////////////////////////////////////////////////////
  41. class CSimpleTable
  42. {
  43. public:
  44. CSimpleTable();
  45. ~CSimpleTable();
  46. HRESULT Attach(IRowset* pRowset);
  47. IRowset* Detach();
  48. HRESULT MoveFirst();
  49. HRESULT MoveNext();
  50. HRESULT Insert();
  51. HRESULT Delete();
  52. HRESULT SetData();
  53. void DiscardChanges()
  54. {
  55. dirty.reset();
  56. }
  57. DBORDINAL GetColumnCount() const
  58. {
  59. return numColumns;
  60. }
  61. DBCOLUMNFLAGS GetColumnFlags(DBORDINAL nOrdinal) const
  62. {
  63. return columnInfo[OrdinalToColumn(nOrdinal)].dwFlags;
  64. }
  65. LPCWSTR GetColumnName(DBORDINAL nOrdinal) const
  66. {
  67. return columnInfo[OrdinalToColumn(nOrdinal)].pwszName;
  68. }
  69. DBTYPE GetColumnType(DBORDINAL nOrdinal) const
  70. {
  71. return columnInfo[OrdinalToColumn(nOrdinal)].wType;
  72. }
  73. DBLENGTH GetLength(DBORDINAL nOrdinal) const;
  74. bool GetOrdinal(LPCWSTR szColumnName, DBORDINAL* pOrdinal) const;
  75. DBSTATUS GetStatus(DBORDINAL nOrdinal) const;
  76. const void* GetValue(DBORDINAL nOrdinal) const
  77. {
  78. return _GetDataPtr(nOrdinal);
  79. }
  80. template <class T>
  81. void SetValue(DBORDINAL nOrdinal, const T& t)
  82. {
  83. *(T*)_GetDataPtr(nOrdinal) = t;
  84. }
  85. void SetValue(DBORDINAL nOrdinal, PCSTR szValue)
  86. {
  87. strcpy((PSTR)_GetDataPtr(nOrdinal), szValue);
  88. }
  89. void SetValue(DBORDINAL nOrdinal, PSTR szValue)
  90. {
  91. strcpy((PSTR)_GetDataPtr(nOrdinal), szValue);
  92. }
  93. bool HasBookmark() const
  94. {
  95. return (numColumns > 0) && (columnInfo->iOrdinal == 0);
  96. }
  97. protected:
  98. enum { FETCH_QUANTUM = 256 }; // The number of rows fetched at a time.
  99. static const DBLENGTH maxColumnWidth = 1024;
  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_