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.

131 lines
4.3 KiB

  1. /****************************************************************************/
  2. /* TRANSASCT.C */
  3. /* Copyright (C) 1995-96 SYWARE Inc., All rights reserved */
  4. /****************************************************************************/
  5. // Commenting #define out - causing compiler error - not sure if needed, compiles
  6. // okay without it.
  7. //#define WINVER 0x0400
  8. #include "precomp.h"
  9. #include "wbemidl.h"
  10. #include <comdef.h>
  11. //smart pointer
  12. _COM_SMARTPTR_TYPEDEF(IWbemServices, IID_IWbemServices);
  13. _COM_SMARTPTR_TYPEDEF(IEnumWbemClassObject, IID_IEnumWbemClassObject);
  14. //_COM_SMARTPTR_TYPEDEF(IWbemContext, IID_IWbemContext );
  15. _COM_SMARTPTR_TYPEDEF(IWbemLocator, IID_IWbemLocator);
  16. #include "drdbdr.h"
  17. /****************************************************************************/
  18. RETCODE INTFUNC TxnEnd(LPDBC lpdbc, BOOL fCommit)
  19. {
  20. LPSTMT lpstmt;
  21. RETCODE err;
  22. /* Just leave if nothing to do */
  23. if (lpdbc->lpISAM == NULL)
  24. return ERR_SUCCESS;
  25. if (lpdbc->lpISAM->fTxnCapable == SQL_TC_NONE)
  26. return ERR_SUCCESS;
  27. /* Close all active statements */
  28. for (lpstmt = lpdbc->lpstmts; lpstmt != NULL; lpstmt = lpstmt->lpNext) {
  29. /* Close the statement */
  30. lpstmt->fStmtType = STMT_TYPE_NONE; /* (to prevent recursive loop) */
  31. err = SQLFreeStmt((HSTMT) lpstmt, SQL_CLOSE);
  32. if ((err != SQL_SUCCESS) && (err != SQL_SUCCESS_WITH_INFO)) {
  33. lpdbc->errcode = lpstmt->errcode;
  34. s_lstrcpy(lpdbc->szISAMError, lpstmt->szISAMError);
  35. return lpdbc->errcode;
  36. }
  37. /* Will the metadata survive the commit/rollback */
  38. if (lpdbc->lpISAM->fSchemaInfoTransactioned) {
  39. /* No. Release all the prepared statements */
  40. if (lpstmt->lpSqlStmt != NULL) {
  41. FreeTree(lpstmt->lpSqlStmt);
  42. lpstmt->lpSqlStmt = NULL;
  43. lpstmt->fPreparedSql = FALSE;
  44. if (lpstmt->lpISAMStatement != NULL) {
  45. ISAMFreeStatement(lpstmt->lpISAMStatement);
  46. lpstmt->lpISAMStatement = NULL;
  47. }
  48. }
  49. }
  50. }
  51. /* Commit/rollback the operation */
  52. if (fCommit)
  53. err = ISAMCommitTxn(lpdbc->lpISAM);
  54. else
  55. err = ISAMRollbackTxn(lpdbc->lpISAM);
  56. if (err != NO_ISAM_ERR) {
  57. ISAMGetErrorMessage(lpdbc->lpISAM, lpdbc->szISAMError);
  58. return err;
  59. }
  60. /* Clear all the transaction flags */
  61. for (lpstmt = lpdbc->lpstmts; lpstmt != NULL; lpstmt = lpstmt->lpNext) {
  62. lpstmt->fISAMTxnStarted = FALSE;
  63. lpstmt->fDMLTxn = FALSE;
  64. }
  65. return ERR_SUCCESS;
  66. }
  67. /****************************************************************************/
  68. RETCODE SQL_API SQLTransact(
  69. HENV henv,
  70. HDBC hdbc,
  71. UWORD fType)
  72. {
  73. //We currently don't support transactions
  74. LPENV lpenv;
  75. LPDBC lpdbc;
  76. RETCODE rc;
  77. //To make guarentee Ole is initialized per thread
  78. COleInitializationManager myOleManager;
  79. MyImpersonator im ((LPDBC)hdbc, "SQLTransact");
  80. if (hdbc != SQL_NULL_HDBC) {
  81. lpdbc = (LPDBC) hdbc;
  82. switch (fType) {
  83. case SQL_COMMIT:
  84. lpdbc->errcode = TxnEnd(lpdbc, TRUE);
  85. if (lpdbc->errcode != ERR_SUCCESS)
  86. return SQL_ERROR;
  87. break;
  88. case SQL_ROLLBACK:
  89. lpdbc->errcode = TxnEnd(lpdbc, FALSE);
  90. if (lpdbc->errcode != ERR_SUCCESS)
  91. return SQL_ERROR;
  92. break;
  93. }
  94. // lpdbc->errcode = ERR_NOTSUPPORTED;
  95. lpdbc->errcode = ERR_SUCCESS;
  96. }
  97. else if (henv != SQL_NULL_HENV) {
  98. lpenv = (LPENV) henv;
  99. for (lpdbc = lpenv->lpdbcs; lpdbc != NULL; lpdbc = lpdbc->lpNext) {
  100. rc = SQLTransact(SQL_NULL_HENV, (HDBC) lpdbc, fType);
  101. if ((rc != SQL_SUCCESS) && (rc != SQL_SUCCESS_WITH_INFO)) {
  102. lpenv->errcode = lpdbc->errcode;
  103. s_lstrcpy(lpenv->szISAMError, lpdbc->szISAMError);
  104. return SQL_ERROR;
  105. }
  106. }
  107. // lpenv->errcode = ERR_NOTSUPPORTED;
  108. lpenv->errcode = ERR_SUCCESS;
  109. }
  110. else
  111. return SQL_INVALID_HANDLE;
  112. return SQL_ERROR;
  113. }
  114. /****************************************************************************/