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.

177 lines
5.8 KiB

  1. /*--------------------------------------------------------------------------
  2. dbsqlcon.h
  3. Connection management class.
  4. Copyright (C) 1995 Microsoft Corporation
  5. All rights reserved.
  6. Authors: Keith Birney (keithbi)
  7. History: 10/13/95 keithbi Created
  8. --------------------------------------------------------------------------*/
  9. #if !defined(__DBSQLCON_H__)
  10. #define __DBSQLCON_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. // #if defined(DEBUG) && defined(INLINE)
  18. // #undef THIS_FILE
  19. // static char BASED_CODE DBSQLCON_H[] = "dbsqlcon.h";
  20. // #define THIS_FILE DBSQLCON_H
  21. // #endif
  22. #include <cpool.h>
  23. #include <dbsqltyp.h>
  24. #define MAX_CONNECT_SEMAPHORES 4096
  25. // partition basis types
  26. #define ACPB_NOT_PARTITIONED 0
  27. #define ACPB_HACCT 1
  28. #define ACPB_LOGIN_NAME 2
  29. #define MAX_SERVER_NAME_LENGTH 45
  30. #define MAX_DB_NAME_LENGTH 64
  31. #define AC_MAX_DB_NAME_LENGTH MAX_DB_NAME_LENGTH
  32. #define AC_MAX_DB_LOGIN_NAME_LENGTH 64
  33. #define AC_MAX_DB_PASSWORD_LENGTH 16
  34. #define AC_MAX_NUMBER_DATABASE_TYPES 4096
  35. class CDBConnection;
  36. extern "C"
  37. {
  38. CDBConnection DbSqlDLL *PdbconnectionNew(CDBQuery *pdbquery);
  39. CDBConnection DbSqlDLL *PdbconnectionNewObsolete(CDBQuery *pdbquery, LONG lDatabaseType, DWORD dwPartitionType, PVOID pvPartitionBasis);
  40. VOID DbSqlDLL ReleaseSystemRef(DBPROCESS *dbproc);
  41. VOID DbSqlDLL ReleaseAllConnections();
  42. VOID DbSqlDLL PerformDatabaseQueryThread(CDBConnection *pdbconnection);
  43. BOOL DbSqlDLL FSetMaxConnectionNum(long lMaxNum);
  44. BOOL DbSqlDLL FSetDBConfigServer(LPTSTR lpszDBMapServer);
  45. BOOL DbSqlDLL FRegisterDBSource(const LONG lType, const WORD wLocatorId, const LPSTR lpszServerName,
  46. const LPSTR lpszDBName, const LPSTR lpszLoginName, const LPSTR lpszPassWord);
  47. //BOOL DbSqlDLL FRegisterDBSourceEx(LPSTR lpszDBSource);
  48. }
  49. class CDBConnection
  50. {
  51. friend CDBConnection DbSqlDLL *PdbconnectionNew(CDBQuery *pdbquery);
  52. friend CDBConnection DbSqlDLL *PdbconnectionNewObsolete(CDBQuery *pdbquery, LONG lDatabaseType, DWORD dwPartitionType, PVOID pvPartitionBasis);
  53. friend VOID DbSqlDLL ReleaseSystemRef(DBPROCESS *dbproc);
  54. friend VOID DbSqlDLL ReleaseAllConnections();
  55. // friend VOID DbSqlDLL PerformDatabaseQueryThread(CDBConnection *pdbconnection);
  56. public:
  57. void * operator new(size_t size);
  58. void operator delete(void *);
  59. static BOOL FInit();
  60. static VOID Terminate();
  61. //private:
  62. static VOID LockList();
  63. static VOID UnlockList();
  64. static CDBConnection *PdbconnectionFindType(LONG lDatabaseType, WORD wLocatorId);
  65. static CDBConnection *PdbconnectionFindDBPROC(DBPROCESS *dbproc);
  66. static UINT UiGetLocatorId(WORD wLocatorTypeId, DWORD dwPartitionType, PVOID pvPartitionBasis, WORD *pwLocatorId);
  67. static UINT UiGetCachedLocator(HACCT hacct, WORD *pwLocatorId);
  68. static VOID StoreLocatorInCache(HACCT hacct, WORD wLocatorId);
  69. static VOID LockLocatorCache();
  70. static VOID UnlockLocatorCache();
  71. static UINT UiLocateSqlServer (WORD wType, WORD wLocatorId, CHAR *szServerName, CHAR *szDBName, CHAR *szUserName, CHAR *szPassword);
  72. //public:
  73. static UINT UiOpenSqlConnection(DBPROCESS **dbproc, CHAR *szServerName, CHAR *szUser, CHAR *szApp, CHAR *szPwd, CHAR *szDB);
  74. static UINT UiIsValidServer(WORD wDatabaseType, WORD wLocatorId, CHAR *szServerName, BOOL *pfValid);
  75. static int __cdecl err_handler(DBPROCESS * dbproc, int severity, int dberr, int oserr, const char * dberrstr, const char * oserrstr);
  76. static int __cdecl msg_handler(DBPROCESS *dbproc, DBINT msgno, int msgstate, int severity, const char *msgtext,
  77. const char *srvname, const char *procname, DBUSMALLINT line);
  78. static LPTHREAD_START_ROUTINE _stdcall DBConnectionValidationThread(UINT i);
  79. static VOID ValidateDBConnections();
  80. VOID AddRef();
  81. VOID Release();
  82. DWORD DwGetTimeEnteredInList() { return m_dwTimeEnteredInList; }
  83. BOOL FCreated() { return m_fCreated; }
  84. VOID AddToConnectionsList();
  85. VOID RemoveFromConnectionsList();
  86. VOID Create();
  87. // UINT PerformDatabaseQuery();
  88. VOID ReleaseClientRef();
  89. DBPROCESS *DbprocGetDBPROC() { return m_dbproc; }
  90. BOOL FPingExistingDBConnection();
  91. //private:
  92. DBPROCESS *m_dbproc;
  93. // HANDLE m_hThread;
  94. // HANDLE m_hSemaphore;
  95. BOOL m_fInUse;
  96. LONG m_lDatabaseType;
  97. PVOID m_pvNext;
  98. ULONG m_cRefCount;
  99. DWORD m_dwTimeEnteredInList;
  100. CDBQuery *m_pdbquery;
  101. BOOL m_fExitNow;
  102. BOOL m_fCreated;
  103. BOOL m_fSystemRefReleased;
  104. WORD m_wLocatorId;
  105. CHAR m_szServer[MAX_SERVER_NAME_LENGTH + 1];
  106. static CPool *ppoolConnection;
  107. static WORD wLocatorTypeId[MAX_CONNECT_SEMAPHORES];
  108. static HANDLE hDBConnectionValidationThread;
  109. static DWORD dwDBConnectionValidationThreadID;
  110. static long lMaxInUseDBConnections;
  111. static BOOL fTerminateCalled;
  112. static HANDLE hDBConnectSemaphore[MAX_CONNECT_SEMAPHORES];
  113. static CRITICAL_SECTION csConnectionsList;
  114. static CRITICAL_SECTION csLocatorCache;
  115. static CDBConnection *pdbconnectionHead;
  116. static BOOL fReportPerformance;
  117. static DWORD dwNumWaitingThreads;
  118. static DWORD dwSecondsSinceStartup;
  119. static CHAR szDBMapSetByComannd[MAX_SERVER_NAME_LENGTH + 1];
  120. CDBConnection(CDBQuery *pdbquery, LONG lDatabaseType, WORD wLocatorId);
  121. ~CDBConnection();
  122. protected:
  123. private:
  124. };
  125. class DBMapEntry
  126. {
  127. public:
  128. LONG m_lType;
  129. WORD m_wLocatorId;
  130. CHAR m_szServerName[MAX_SERVER_NAME_LENGTH + 1];
  131. CHAR m_szDBName[MAX_DB_NAME_LENGTH + 1];
  132. CHAR m_szLoginName[AC_MAX_DB_LOGIN_NAME_LENGTH + 1];
  133. CHAR m_szPassWord[AC_MAX_DB_PASSWORD_LENGTH +1];
  134. //void* operator new(size_t size);
  135. //void operator delete(void *pvMem);
  136. DBMapEntry(){}
  137. DBMapEntry(const LONG, const WORD, const LPSTR, const LPSTR, const LPSTR, const LPSTR);
  138. ~DBMapEntry(){}
  139. INT NGetEntry(LPSTR lpszServerName, LPSTR lpszDBName,
  140. LPSTR lpszLoginName, LPSTR lpszPassWord);
  141. };
  142. #endif // #if !defined(__DBSQLCON_H__)