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.

239 lines
7.1 KiB

  1. /*--------------------------------------------------------------------------
  2. dbsqlqry.h
  3. An additional layer to use in making dblib calls.
  4. Copyright (C) 1995 Microsoft Corporation
  5. All rights reserved.
  6. Authors: Keith Birney (keithbi)
  7. History: 07/19/95 keithbi Created
  8. --------------------------------------------------------------------------*/
  9. #if !defined(__DBSQLQRY_H__)
  10. #define __DBSQLQRY_H__
  11. #define DBNTWIN32
  12. #pragma warning (disable:4121)
  13. #include <sqlfront.h>
  14. #pragma warning (default:4121)
  15. #include <sqldb.h>
  16. // THIS_FILE is defined in source files
  17. //
  18. // #if defined(DEBUG) && defined(INLINE)
  19. // #undef THIS_FILE
  20. // static char BASED_CODE DBSQLQRY_H[] = "dbsqlqry.h";
  21. // #define THIS_FILE DBSQLQRY_H
  22. // #endif
  23. #include <cpool.h>
  24. class CDBConnection;
  25. class CDBQueryBase;
  26. class CDBQuery;
  27. typedef UINT (FNPROCESSROWCALLBACK)(CDBQuery *, DWORD, DWORD, PVOID);
  28. typedef FNPROCESSROWCALLBACK *PFNPROCESSROWCALLBACK;
  29. class CDBQueryBase
  30. {
  31. public:
  32. virtual VOID Release() = 0;
  33. virtual VOID ZeroDirtyParams() = 0;
  34. virtual VOID AddVarParam(WORD wDataType, PVOID pvParamValue, WORD wDataLen) = 0;
  35. virtual VOID AddSzParam(WORD wDataType, PVOID pvParamValue) = 0;
  36. virtual VOID AddParam(WORD wDataType, PVOID pvParamValue) = 0;
  37. virtual VOID AddReturnParam(WORD wDataType, PVOID pvParamValue) = 0;
  38. virtual VOID AddVarReturnParam(WORD wDataType, PVOID pvParamValue, WORD wDataLen, WORD wMaxLen) = 0;
  39. virtual VOID AddResultsSet() = 0;
  40. virtual VOID AddColumnToResultsSet(WORD wDataType) = 0;
  41. virtual VOID AddVarColumnToResultsSet(WORD wDataType, WORD wDataLen) = 0;
  42. virtual INT IGetReturnStatus() = 0;
  43. virtual VOID SetProcessRowCallback(PFNPROCESSROWCALLBACK pfnprocessrowcallback, PVOID pv) = 0;
  44. virtual UINT UiGetResultRow(PVOID pvFirst, ...) = 0;
  45. virtual UINT UiGetResultRowPtrs(PBYTE *pbFirst, ...) = 0;
  46. virtual BOOL FQueryComplete() = 0;
  47. virtual BOOL FQuerySuccess() = 0;
  48. virtual VOID AddRef() = 0;
  49. virtual VOID CancelExecution() = 0;
  50. virtual BYTE BGetDatabaseType() = 0;
  51. virtual VOID SetDatabaseType(BYTE bDatabaseType) = 0;
  52. virtual UINT UiGetAPIReturnCode() = 0;
  53. virtual VOID SetUserData(PVOID pv) = 0;
  54. virtual BOOL FIsReentrantCall() = 0;
  55. virtual UINT UiWaitUntilDone(DWORD dwTimeout) = 0;
  56. virtual VOID SetAPIReturnCode(UINT uiRet) = 0;
  57. virtual VOID SetRetryOnDBFail() = 0;
  58. virtual VOID SetPartitionInfo(DWORD dwPartitionType, PVOID pvData) = 0;
  59. virtual DWORD DwGetPartitionType() = 0;
  60. virtual PVOID PvGetPartitionBasis() = 0;
  61. virtual UINT UiWaitUntilResults(DWORD dwTimeout) = 0;
  62. virtual UINT UiGetNextRow(PVOID pvFirst, ...) = 0;
  63. virtual UINT UiGetNextResultsSet() = 0;
  64. };
  65. class CDBQuery;
  66. extern "C"
  67. {
  68. CDBQuery DbSqlDLL *PdbqueryNew(WORD wDatabaseType, CHAR *szStoredProcedureName);
  69. }
  70. #define AC_MAX_NUMBER_DBPARAMS 32
  71. #define AC_DB_OBJECT_NAME_SIZE 32
  72. #define AC_MAX_NUMBER_RESULTS_SETS 5
  73. #define AC_MAX_NUMBER_COLUMNS 32
  74. #define AC_MAX_QUERIES_IN_POOL 1024
  75. #define AC_RESULTS_ROW_BUFFER_WIDTH 2048
  76. struct DBPARAM
  77. {
  78. WORD wDataType;
  79. WORD wDataLen;
  80. WORD wMaxLen;
  81. WORD wStatus;
  82. PBYTE pbParamValue;
  83. };
  84. struct DBRESULTCOLUMN
  85. {
  86. WORD wDataType;
  87. WORD wDataLen;
  88. PBYTE pbData;
  89. };
  90. struct DBRESULTINFO
  91. {
  92. DWORD dwNumberOfColumns;
  93. DBRESULTCOLUMN dbrescol[AC_MAX_NUMBER_COLUMNS];
  94. };
  95. class CDBQuery : public CDBQueryBase
  96. {
  97. friend CDBQuery DbSqlDLL *PdbqueryNew(WORD wDatabaseType, CHAR *szStoredProcedureName);
  98. public:
  99. void * operator new(size_t size);
  100. void operator delete(void *);
  101. VOID AddRef();
  102. VOID Release();
  103. VOID ZeroDirtyParams();
  104. VOID AddVarParam(WORD wDataType, PVOID pvParamValue, WORD wDataLen);
  105. VOID AddSzParam(WORD wDataType, PVOID pvParamValue);
  106. VOID AddParam(WORD wDataType, PVOID pvParamValue);
  107. VOID AddReturnParam(WORD wDataType, PVOID pvParamValue);
  108. VOID AddVarReturnParam(WORD wDataType, PVOID pvParamValue, WORD wDataLen, WORD wMaxLen);
  109. VOID AddResultsSet();
  110. VOID AddColumnToResultsSet(WORD wDataType);
  111. VOID AddVarColumnToResultsSet(WORD wDataType, WORD wDataLen);
  112. INT IGetReturnStatus() { return m_iRetStatus; }
  113. VOID SetProcessRowCallback(PFNPROCESSROWCALLBACK pfnprocessrowcallback, PVOID pv);
  114. UINT UiGetResultRow(PVOID pvFirst, ...);
  115. UINT UiGetResultRowPtrs(PBYTE *pbFirst, ...);
  116. UINT UiWaitUntilResults(DWORD dwTimeout);
  117. UINT UiGetNextRow(PVOID pvFirst, ...);
  118. UINT UiGetNextResultsSet();
  119. PVOID PvGetResultsBuffer();
  120. BOOL FQueryComplete() { return m_fQueryIsComplete; }
  121. BOOL FQuerySuccess() { return m_fQuerySucceeded; }
  122. VOID CancelExecution();
  123. BYTE BGetDatabaseType() { return m_bDatabaseType; }
  124. VOID SetDatabaseType(BYTE bDatabaseType) { m_bDatabaseType = bDatabaseType; }
  125. UINT UiGetAPIReturnCode() { return m_uiAPIReturnCode; }
  126. VOID SetUserData(PVOID pv);
  127. VOID CleanupCallback();
  128. BOOL FIsReentrantCall() { return m_fReentrantCallbackCall; }
  129. INT IGetNumberOfRowsProcessed(INT iResultsSet) { return m_iRowNum[iResultsSet]; }
  130. INT IGetNumberOfResultsSetsProcessed() { return m_iResultsNum + 1; }
  131. VOID SetBufferResultsSets(LONG lMaxRowsToBuffer);
  132. UINT UiAddRowToBuffer();
  133. UINT UiWaitUntilDone(DWORD dwTimeout);
  134. VOID SetAPIReturnCode(UINT uiRet) { m_uiAPIReturnCode = uiRet; }
  135. VOID SetRetryOnDBFail() { m_fRetryOnFail = TRUE; }
  136. VOID SetPartitionInfo(DWORD dwPartitionType, PVOID pvData) { m_dwPartitionType = dwPartitionType;
  137. m_pvPartitionBasis = pvData; }
  138. DWORD DwGetPartitionType() { return m_dwPartitionType; }
  139. PVOID PvGetPartitionBasis() { return m_pvPartitionBasis; }
  140. static BOOL FInit();
  141. static VOID Terminate();
  142. static BOOL FQueryCompletePv(PVOID pv);
  143. protected:
  144. CDBQuery(BYTE bDatabaseType, CHAR *szStoredProcedureName);
  145. ~CDBQuery();
  146. private:
  147. UINT UiDoDatabaseQuery(DBPROCESS *dbproc);
  148. CDBConnection* m_pdbconnection;
  149. DBPROCESS* m_dbproc;
  150. RETCODE m_retcodeLastDbresultsReturn;
  151. STATUS m_statusLastDbnextrowReturn;
  152. BOOL m_fReentrantCallbackCall;
  153. BOOL m_fRetryOnFail;
  154. CHAR m_szStoredProcedureName[AC_DB_OBJECT_NAME_SIZE];
  155. BOOL m_fQueryIsComplete;
  156. BOOL m_fQuerySucceeded;
  157. BOOL m_fQueryCanceled;
  158. BOOL m_fBufferResultsSets;
  159. LONG m_lMaxRowsToBuffer;
  160. LONG m_cbBytesInBuffer;
  161. ULONG m_cRefCount;
  162. BYTE m_bDatabaseType;
  163. BYTE m_bNumberOfParams;
  164. BYTE m_bNumberOfReturnParams;
  165. BYTE m_bNumberOfResultsSets;
  166. INT m_iRetStatus;
  167. INT m_iResultsNum;
  168. INT m_iRowNum[AC_MAX_NUMBER_RESULTS_SETS];
  169. UINT m_uiAPIReturnCode;
  170. PVOID m_pvUserData;
  171. PVOID m_pvBufferedResultsSets;
  172. PBYTE m_pbCurrentBufferOffset;
  173. PFNPROCESSROWCALLBACK m_pfnProcessRowCallback;
  174. CRITICAL_SECTION m_csCallbackCS;
  175. DWORD m_dwPartitionType;
  176. PVOID m_pvPartitionBasis;
  177. DBPARAM m_dbparam[AC_MAX_NUMBER_DBPARAMS];
  178. DBRESULTINFO m_dbresinfo[AC_MAX_NUMBER_RESULTS_SETS];
  179. BYTE m_bResultsSetRowBuffer[AC_RESULTS_ROW_BUFFER_WIDTH];
  180. static BOOL fUseSuppliedDataLen[256];
  181. static DWORD dwSqlBindValues[256];
  182. static DWORD dwSqlDataLen[256];
  183. static CPool *ppoolQuery;
  184. static BOOL fTerminateCalled;
  185. };
  186. #define ACDB_CONTINUE 0
  187. #define ACDB_CANCEL 1
  188. #define ACDB_RESUBMIT 2
  189. #define ACDB_CLEANUP 0xFFFFFFFF
  190. #endif // #if !defined(__DBSQLQRY_H__)