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.

148 lines
7.7 KiB

  1. //***************************************************************************
  2. //
  3. // (c) 1999-2001 by Microsoft Corp. All Rights Reserved.
  4. //
  5. // sqlexec.h
  6. //
  7. // cvadai 6-May-1999 created.
  8. //
  9. //***************************************************************************
  10. #ifndef _SQLEXEC_H_
  11. #define _SQLEXEC_H_
  12. // This file defines a class that maintains a cache of
  13. // SQL connections. Each instance of this class only
  14. // contains one set of logon credentials.
  15. // Each controller by default is only entitled to
  16. // a maximum of 20 connections.
  17. // ===================================================
  18. #define SQL_STRING_LIMIT 3970
  19. #define REPDRVR_NAME_LIMIT REPDRVR_MAX_LONG_STRING_SIZE
  20. #define REPDRVR_PATH_LIMIT 450
  21. #include <std.h>
  22. #include <comutil.h>
  23. #include <oledb.h>
  24. #include <oledberr.h>
  25. #include <seqstream.h>
  26. #include <objcache.h>
  27. #include <sqlcache.h>
  28. #include <wbemint.h>
  29. #include <repcache.h>
  30. #include <coresvc.h>
  31. //*******************************************************
  32. //
  33. // CSQLExecute
  34. //
  35. //*******************************************************
  36. // This needs to deal with blob data,
  37. // and support batching.
  38. class _declspec( dllexport ) CSQLExecute
  39. {
  40. public:
  41. static HRESULT ExecuteQuery(IDBCreateCommand *pCmd, LPCWSTR lpSQL, IRowset **ppIRowset = NULL, DWORD *dwNumRows = NULL, ...);
  42. static HRESULT ExecuteQuery(IDBInitialize *pDBInit, LPCWSTR lpSQL, IRowset **ppIRowset = NULL, DWORD *dwNumRows = NULL);
  43. static HRESULT ExecuteQueryAsync(IDBInitialize *pDBInit, LPCWSTR lpSQL, IDBAsynchStatus **ppIAsync, DWORD *dwNumRows = NULL);
  44. static HRESULT IsDataReady(IDBAsynchStatus *pIAsync);
  45. static HRESULT CancelQuery(IDBAsynchStatus *pIAsync);
  46. static HRESULT GetNumColumns(IRowset *pIRowset, IMalloc *pMalloc, int &iNumCols);
  47. static HRESULT GetDataType(IRowset *pIRowset, int iPos, IMalloc *pMalloc, DWORD &dwType,
  48. DWORD &dwSize, DWORD &dwPrec, DWORD &dwScale, LPWSTR *lpColumnName = NULL);
  49. static HRESULT GetColumnValue(IRowset *pIRowset, int iPos, IMalloc *pMalloc, HROW **pRow, VARIANT &vValue, LPWSTR * lpColumnName=NULL);
  50. static HRESULT ReadImageValue (IRowset *pRowset, int iPos, HROW **pRow, BYTE **pBuffer, DWORD &dwLen);
  51. static HRESULT WriteImageValue(IDBCreateCommand *pCmd, LPCWSTR lpSQL, int iPos, BYTE *pValue, DWORD dwLen);
  52. static HRESULT GetWMIError(IUnknown *pErrorObj);
  53. static HRESULT GetWMIError(long ErrorID);
  54. static void SetDBNumeric (DB_NUMERIC &Id, SQL_ID ObjId);
  55. static void ClearBindingInfo(DBBINDING *binding);
  56. static void SetBindingInfo(DBBINDING *binding, ULONG iOrdinal, ULONG uSize, DBPARAMIO io, ULONG maxlen, DBTYPE type, BYTE bPrecision);
  57. static void SetParamBindInfo (DBPARAMBINDINFO &BindInfo, LPWSTR pszType, LPWSTR lpName, ULONG uSize, DWORD dwFlags, BYTE bPrecision);
  58. static void GetInt64 (DB_NUMERIC *pId, wchar_t **ppBuffer);
  59. static __int64 GetInt64 (DB_NUMERIC *pId);
  60. static void SetVariant(DWORD dwType, VARIANT *pValue, BYTE *pData, DWORD dwTargetType);
  61. protected:
  62. CSQLExecute(){};
  63. ~CSQLExecute(){};
  64. };
  65. //***************************************************************************
  66. //
  67. // CSQLExecProcedure - class for executing procedures as efficiently as
  68. // possible.
  69. //
  70. //***************************************************************************
  71. class _declspec (dllexport) CSQLExecProcedure
  72. {
  73. typedef std::vector <SQL_ID> SQLIDs;
  74. public:
  75. static HRESULT GetObjectIdByPath (CSQLConnection *pConn, LPCWSTR lpPath, SQL_ID &dObjectId, SQL_ID &dClassId,
  76. SQL_ID *dScopeId, BOOL *bDeleted=NULL); // sp_GetInstanceID
  77. static HRESULT GetHierarchy(CSQLConnection *pConn, SQL_ID dClassId); // sp_GetChildClassList, sp_GetParentList
  78. static HRESULT GetNextUnkeyedPath(CSQLConnection *pConn, SQL_ID dClassId, _bstr_t &sNewPath); // sp_GetNextUnkeyedPath
  79. static HRESULT GetNextKeyhole(CSQLConnection *pConn, DWORD iPropertyId, SQL_ID &dNewId); // sp_GetNextKeyhole
  80. static HRESULT DeleteProperty(CSQLConnection *pConn, DWORD iPropertyId); // sp_DeleteClassData
  81. static HRESULT DeleteInstanceData (CSQLConnection *pConn, SQL_ID dObjectId, DWORD iPropertyId, DWORD iPos = -1);
  82. static HRESULT CheckKeyMigration(CSQLConnection *pConn, LPWSTR lpObjectKey, LPWSTR lpClassName, SQL_ID dClassId, SQL_ID dScopeID,
  83. SQL_ID *pIDs, DWORD iNumIDs);
  84. static HRESULT NeedsToCheckKeyMigration(BOOL &bCheck);
  85. static HRESULT Execute (CSQLConnection *pConn, LPCWSTR lpProcName, CWStringArray &arrValues,
  86. IRowset **ppIRowset);
  87. static HRESULT EnumerateSubScopes (CSQLConnection *pConn, SQL_ID dScopeId);
  88. static HRESULT InsertScopeMap (CSQLConnection *pConn, SQL_ID dScopeId, LPCWSTR lpScopePath, SQL_ID );
  89. static HRESULT GetClassInfo (CSQLConnection *pConn, SQL_ID dClassId, SQL_ID &dSuperClassId, BYTE **pBuffer, DWORD &dwBuffLen);
  90. static HRESULT HasInstances(CSQLConnection *pConn, SQL_ID dClassId, SQL_ID *pDerivedIds, DWORD iNumDerived, BOOL &bInstancesExist);
  91. static HRESULT InsertClass (CSQLConnection *pConn, LPCWSTR lpClassName, LPCWSTR lpObjectKey, LPCWSTR lpObjectPath, SQL_ID dScopeID,
  92. SQL_ID dParentClassId, SQL_ID dDynasty, DWORD iState, BYTE *pClassBuff, DWORD dwClassBuffLen, DWORD iClassFlags, DWORD iInsertFlags, SQL_ID &dNewId);
  93. static HRESULT UpdateClassBlob (CSQLConnection *pConn, SQL_ID dClassId, _IWmiObject *pObj);
  94. static HRESULT InsertClassData (CSQLConnection *pConn, IWbemClassObject *pObj, CSchemaCache *pCache,SQL_ID dScopeId, SQL_ID dClassId, LPCWSTR lpPropName,
  95. DWORD CIMType, DWORD StorageType,LPCWSTR lpValue, SQL_ID dRefClassId, DWORD iPropID, DWORD iFlags,
  96. DWORD iFlavor, BOOL iSkipValid, DWORD &iNewPropId, SQL_ID dOrigClassId=0, BOOL *bIsKey = NULL);
  97. static HRESULT InsertBlobData (CSQLConnection *pConn, SQL_ID dClassId, SQL_ID dObjectId, DWORD iPropertyId, BYTE *pImage, DWORD iPos, DWORD dwNumBytes);
  98. static HRESULT InsertPropertyBatch (CSQLConnection *pConn, LPCWSTR lpObjectKey, LPCWSTR lpPath, LPCWSTR lpClassName,
  99. SQL_ID dClassId, SQL_ID dScopeId, DWORD iFlags, InsertPropValues *pVals, DWORD iNumVals, SQL_ID &dNewObjectId);
  100. static HRESULT InsertBatch (CSQLConnection *pConn, SQL_ID dObjectId, SQL_ID dScopeId, SQL_ID dClassId,
  101. InsertQfrValues *pVals, DWORD iNumVals=10);
  102. static HRESULT ObjectExists (CSQLConnection *pConn,SQL_ID dId, BOOL &bExists, SQL_ID *dClassId, SQL_ID *dScopeId, BOOL bDeletedOK = FALSE);
  103. static HRESULT RenameSubscopes (CSQLConnection *pConn, LPWSTR lpOldPath, LPWSTR lpOldKey, LPWSTR lpNewPath, LPWSTR lpNewKey);
  104. static HRESULT GetSecurityDescriptor(CSQLConnection *pConn, SQL_ID dObjectId,
  105. PNTSECURITY_DESCRIPTOR * ppSD, DWORD &dwBuffLen,
  106. DWORD dwFlags);
  107. static HRESULT EnumerateSecuredChildren(CSQLConnection *pConn, CSchemaCache *pCache, SQL_ID dObjectId, SQL_ID dClassId, SQL_ID dScopeId,
  108. SQLIDs &ObjIds, SQLIDs &ClassIds, SQLIDs &ScopeIds);
  109. // Special functions for handling ESS
  110. static HRESULT InsertUncommittedEvent (CSQLConnection *pConn,LPCWSTR lpGUID, LPWSTR lpNamespace, LPWSTR lpClassName, IWbemClassObject *pOldObj,
  111. IWbemClassObject *pNewObj, CSchemaCache *pCache);
  112. static HRESULT DeleteUncommittedEvents (CSQLConnection *pConn,LPCWSTR lpGUID, CSchemaCache *pCache, CObjectCache *pObjCache);
  113. static HRESULT CommitEvents(CSQLConnection *pConn, _IWmiCoreServices *pESS, LPCWSTR lpNamespace,
  114. LPCWSTR lpGUID, CSchemaCache *pCache, CObjectCache *pObjCache);
  115. private:
  116. CSQLExecProcedure() {};
  117. ~CSQLExecProcedure() {};
  118. };
  119. #endif // _SQLEXEC_H_