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.

195 lines
5.4 KiB

  1. //--------------------------------------------------------------------------
  2. // Session.cpp
  3. //--------------------------------------------------------------------------
  4. #include "pch.hxx"
  5. #include "session.h"
  6. #include "listen.h"
  7. #include "database.h"
  8. #include "wrapwide.h"
  9. //--------------------------------------------------------------------------
  10. // CreateDatabaseSession
  11. //--------------------------------------------------------------------------
  12. HRESULT CreateDatabaseSession(IUnknown *pUnkOuter, IUnknown **ppUnknown)
  13. {
  14. // Trace
  15. TraceCall("CreateDatabaseSession");
  16. // Initialize
  17. *ppUnknown = NULL;
  18. // Create me
  19. CDatabaseSession *pNew = new CDatabaseSession();
  20. if (NULL == pNew)
  21. return TraceResult(E_OUTOFMEMORY);
  22. // Cast to unknown
  23. *ppUnknown = SAFECAST(pNew, IDatabaseSession *);
  24. // Done
  25. return(S_OK);
  26. }
  27. //--------------------------------------------------------------------------
  28. // CDatabaseSession::CDatabaseSession
  29. //--------------------------------------------------------------------------
  30. CDatabaseSession::CDatabaseSession(void)
  31. {
  32. TraceCall("CDatabaseSession::CDatabaseSession");
  33. m_cRef = 1;
  34. ListenThreadAddRef();
  35. }
  36. //--------------------------------------------------------------------------
  37. // CDatabaseSession::~CDatabaseSession
  38. //--------------------------------------------------------------------------
  39. CDatabaseSession::~CDatabaseSession(void)
  40. {
  41. TraceCall("CDatabaseSession::~CDatabaseSession");
  42. ListenThreadRelease();
  43. }
  44. //--------------------------------------------------------------------------
  45. // CDatabaseSession::AddRef
  46. //--------------------------------------------------------------------------
  47. STDMETHODIMP_(ULONG) CDatabaseSession::AddRef(void)
  48. {
  49. TraceCall("CDatabaseSession::AddRef");
  50. return InterlockedIncrement(&m_cRef);
  51. }
  52. //--------------------------------------------------------------------------
  53. // CDatabaseSession::Release
  54. //--------------------------------------------------------------------------
  55. STDMETHODIMP_(ULONG) CDatabaseSession::Release(void)
  56. {
  57. TraceCall("CDatabaseSession::Release");
  58. LONG cRef = InterlockedDecrement(&m_cRef);
  59. if (0 == cRef)
  60. delete this;
  61. return (ULONG)cRef;
  62. }
  63. //--------------------------------------------------------------------------
  64. // CDatabaseSession::QueryInterface
  65. //--------------------------------------------------------------------------
  66. STDMETHODIMP CDatabaseSession::QueryInterface(REFIID riid, LPVOID *ppv)
  67. {
  68. // Locals
  69. HRESULT hr=S_OK;
  70. // Stack
  71. TraceCall("CDatabaseSession::QueryInterface");
  72. // Find IID
  73. if (IID_IUnknown == riid)
  74. *ppv = (IUnknown *)this;
  75. else if (IID_IDatabaseSession == riid)
  76. *ppv = (IDatabaseSession *)this;
  77. else
  78. {
  79. *ppv = NULL;
  80. hr = TraceResult(E_NOINTERFACE);
  81. goto exit;
  82. }
  83. // AddRef It
  84. ((IUnknown *)*ppv)->AddRef();
  85. exit:
  86. // Done
  87. return(hr);
  88. }
  89. //--------------------------------------------------------------------------
  90. // CDatabaseSession::OpenDatabase
  91. //--------------------------------------------------------------------------
  92. STDMETHODIMP CDatabaseSession::OpenDatabase(LPCSTR pszFile, OPENDATABASEFLAGS dwFlags,
  93. LPCTABLESCHEMA pSchema, IDatabaseExtension *pExtension, IDatabase **ppDB)
  94. {
  95. // Locals
  96. HRESULT hr=S_OK;
  97. LPWSTR pwszFile=NULL;
  98. // Trace
  99. TraceCall("CDatabaseSession::OpenDatabase");
  100. // Convert to Unicode
  101. IF_NULLEXIT(pwszFile = ConvertToUnicode(CP_ACP, pszFile));
  102. // Open It
  103. IF_FAILEXIT(hr = OpenDatabaseW(pwszFile, dwFlags, pSchema, pExtension, ppDB));
  104. exit:
  105. // Cleanup
  106. g_pMalloc->Free(pwszFile);
  107. // Done
  108. return(hr);
  109. }
  110. //--------------------------------------------------------------------------
  111. // CDatabaseSession::OpenDatabaseW
  112. //--------------------------------------------------------------------------
  113. STDMETHODIMP CDatabaseSession::OpenDatabaseW(LPCWSTR pszFile, OPENDATABASEFLAGS dwFlags,
  114. LPCTABLESCHEMA pSchema, IDatabaseExtension *pExtension, IDatabase **ppDB)
  115. {
  116. // Locals
  117. HRESULT hr=S_OK;
  118. CDatabase *pDatabase=NULL;
  119. // Trace
  120. TraceCall("CDatabaseSession::OpenDatabaseW");
  121. // Create a pDatabase
  122. IF_NULLEXIT(pDatabase = new CDatabase);
  123. // Open It
  124. IF_FAILEXIT(hr = pDatabase->Open(pszFile, dwFlags, pSchema, pExtension));
  125. // Cast It
  126. (*ppDB) = (IDatabase *)pDatabase;
  127. // Don't Free It
  128. pDatabase = NULL;
  129. exit:
  130. // Cleanup
  131. SafeRelease(pDatabase);
  132. // Done
  133. return(hr);
  134. }
  135. //--------------------------------------------------------------------------
  136. // CDatabaseSession::OpenQuery
  137. //--------------------------------------------------------------------------
  138. STDMETHODIMP CDatabaseSession::OpenQuery(IDatabase *pDatabase, LPCSTR pszQuery,
  139. IDatabaseQuery **ppQuery)
  140. {
  141. // Locals
  142. HRESULT hr=S_OK;
  143. CDatabaseQuery *pQuery=NULL;
  144. // Trace
  145. TraceCall("CDatabaseSession::OpenQuery");
  146. // Create a pDatabase
  147. IF_NULLEXIT(pQuery = new CDatabaseQuery);
  148. // Open It
  149. IF_FAILEXIT(hr = pQuery->Initialize(pDatabase, pszQuery));
  150. // Cast It
  151. (*ppQuery) = (IDatabaseQuery *)pQuery;
  152. // Don't Free It
  153. pQuery = NULL;
  154. exit:
  155. // Cleanup
  156. SafeRelease(pQuery);
  157. // Done
  158. return(hr);
  159. }