Beispiel #1
0
static void TRANSACTION_ChangeState (
    unsigned long txHigh, 
    unsigned long txLow, 
    CString& strOperation,
    CTypedPtrList < CObList, CaTableTransactionItemData* >& ls)
{
	unsigned long lLow, lHigh;
	CaTableTransactionItemData* pObj = NULL;
	POSITION pos = ls.GetHeadPosition();
	while (pos != NULL)
	{
		pObj = ls.GetNext (pos);
		pObj->GetTransactionID (lHigh, lLow);
		if (txHigh == lHigh && txLow == lLow)
		{
			if (strOperation.CompareNoCase (_T("COMMIT")) == 0)
			{
				pObj->SetCommit  (TRUE);
				pObj->SetJournal (TRUE);
			}
			else
			if (strOperation.CompareNoCase (_T("ABORT")) == 0)
			{
				pObj->SetCommit  (FALSE);
				pObj->SetJournal (TRUE);
			}
			else
			if (strOperation.CompareNoCase (_T("COMMITNJ")) == 0)
			{
				pObj->SetCommit  (TRUE);
				pObj->SetJournal (FALSE);
			}
			else
			if (strOperation.CompareNoCase (_T("ABORTNJ")) == 0)
			{
				pObj->SetCommit  (FALSE);
				pObj->SetJournal (FALSE);
			}
			else
			{
				//
				// String in OPERATION in not in ('commit', 'abort', 'commitnj', 'abortnj')
				ASSERT (FALSE);
			}
		}
	}
}
Beispiel #2
0
BOOL IJA_llQueryTableTransaction (
    CaQueryTransactionInfo* pQueryInfo,
    CTypedPtrList<CObList, CaColumn*>* pListColumn,
    CTypedPtrList < CObList, CaTableTransactionItemData* >& listTransaction)
{
	CString strDatabase;
	CString strDatabaseOwner;
	CString strTable;
	CString strTableOwner;
	CString strStatement;

	pQueryInfo->GetDatabase (strDatabase, strDatabaseOwner);
	pQueryInfo->GetTable (strTable, strTableOwner);

	//
	// Open the session:
	CaTemporarySession session (pQueryInfo->GetNode(), strDatabase);
	if (!session.IsConnected())
	{
		//
		// Failedto get Session.
		CString strMsg;
		strMsg.LoadString (IDS_FAIL_TO_GETSESSION);
		AfxMessageBox (strMsg);
		return FALSE;
	}

	CString strTempTable = _T("");
	CString csGranteeList = _T(""); /* no grantee list required here */
	BOOL bOK = IJA_TableAuditdbOutput (pQueryInfo, &session, strTempTable, pListColumn, csGranteeList);
	if (!bOK) {
		session.Release(SESSION_ROLLBACK);
		return FALSE;
	}
	BOOL bOnLocal = session.IsLocalNode();
	//
	// STEP 1: Select row that are INSERT, DELETE, REPOLD, REPNEW
	// Select the rows (table transactions) from the newly created Table:
	CString strSessionPrefix = _T("");
	if (bOnLocal)
		strSessionPrefix = _T("session.");

	strStatement.Format (
		_T("select * from %s%s where operation  in ('repold', 'repnew', 'append', 'insert', 'delete')"),
		(LPCTSTR)strSessionPrefix,
		(LPCTSTR)strTempTable);
	CaIjaCursor cursor(1, strStatement);
	if (cursor.Open())
	{
		int nCount = 0;
		CStringList listData;
		CString strItem1;
		CString strItem2;

		while (cursor.Fetch(listData, nCount))
		{
			CaTableTransactionItemData* pTran = new CaTableTransactionItemData();

			POSITION pos = listData.GetHeadPosition();
			ASSERT (listData.GetCount() >= 10); // At least 10 columns;
			if (listData.GetCount() < 10)
			{
				delete pTran;
				return FALSE;
			}
			pTran->SetTable (strTable);
			pTran->SetTableOwner (strTableOwner);

			if (pos != NULL)
			{
				// LSN:
				strItem1 = listData.GetNext (pos);
				strItem2 = listData.GetNext (pos);
				pTran->SetLsn (_ttoul(strItem1), _ttoul(strItem2));
				// TID:
				strItem1 = listData.GetNext (pos); 
				pTran->SetTid(_ttol(strItem1));
				// Date:
				strItem1 = listData.GetNext (pos);
				pTran->SetDate(strItem1);
				// User Name:
				strItem1 = listData.GetNext (pos);
				pTran->SetUser (strItem1);
				// Operation:
				strItem1 = listData.GetNext (pos);
				if (strItem1.CompareNoCase (_T("insert")) == 0 || strItem1.CompareNoCase (_T("append")) == 0)
					pTran->SetOperation (T_INSERT);
				else
				if (strItem1.CompareNoCase (_T("delete")) == 0)
					pTran->SetOperation (T_DELETE);
				else
				if (strItem1.CompareNoCase (_T("repold")) == 0)
					pTran->SetOperation (T_BEFOREUPDATE);
				else
				if (strItem1.CompareNoCase (_T("repnew")) == 0)
					pTran->SetOperation (T_AFTERUPDATE);
				else
				{
					ASSERT (FALSE);
					pTran->SetOperation (T_UNKNOWN);
				}
				// Transaction:
				strItem1 = listData.GetNext (pos);
				strItem2 = listData.GetNext (pos);
				pTran->SetTransactionID (_ttoul(strItem1), _ttoul(strItem2));
				// Ignore:
				strItem1 = listData.GetNext (pos);
				strItem2 = listData.GetNext (pos);
			}
			pTran->SetCommit  (TRUE);
			pTran->SetJournal (TRUE);

			CStringList& listAuditedData = pTran->GetListData();
			while (pos != NULL)
			{
				strItem1 = listData.GetNext (pos);
				listAuditedData.AddTail(strItem1);
			}

			listTransaction.AddTail (pTran);
			listData.RemoveAll();
		}

		cursor.Close();
	}

	//
	// STEP 2: Select rows that are COMMIT, ABORT, COMMITNJ, ABORTNJ
	//         to update the previous select result if the rows are commit, abort, ...
	// Select the rows (table transactions) from the newly created Table:
	strStatement.Format (
		_T("select * from %s%s where operation  in ('commit', 'abort', 'commitnj', 'abortnj')"),
		(LPCTSTR)strSessionPrefix,
		(LPCTSTR)strTempTable);

	CaIjaCursor cursor2(2, strStatement);
	if (cursor2.Open())
	{
		CaTableTransactionItemData* pFound = NULL;
		int nCount = 0;
		CStringList listData;
		CString strItem1;
		CString strItem2;
		CString strOperation;

		while (cursor2.Fetch(listData, nCount))
		{
			POSITION pos = listData.GetHeadPosition();
			ASSERT (listData.GetCount() >= 10); // At least 10 columns;
			if (listData.GetCount() < 10)
				return FALSE;

			if (pos != NULL)
			{
				// LSN:
				strItem1 = listData.GetNext (pos);
				strItem2 = listData.GetNext (pos);
				// Ignore:
				strItem1 = listData.GetNext (pos); 
				// Date:
				strItem1 = listData.GetNext (pos);
				// User Name:
				strItem1 = listData.GetNext (pos);
				// Operation:
				strOperation = listData.GetNext (pos);

				// Transaction:
				strItem1 = listData.GetNext (pos);
				strItem2 = listData.GetNext (pos);
				TRANSACTION_ChangeState (_ttoul(strItem1), _ttoul(strItem2), strOperation, listTransaction);
				// Ignore:
				strItem1 = listData.GetNext (pos);
				strItem2 = listData.GetNext (pos);
			}
			listData.RemoveAll();
		}

		cursor2.Close();
	}

	//
	// Make sure that the temporary table has been destroyed:
	if (!bOnLocal && bOK && !strTempTable.IsEmpty()) 
	{
		strStatement.Format ( _T("drop table %s"), (LPCTSTR)strTempTable);
		CaLowlevelAddAlterDrop param (pQueryInfo->GetNode(), strDatabase, strStatement);
		param.NeedSession(FALSE); // Use the current open session.
		param.SetStatement(strStatement);
		if (!param.ExecuteStatement(NULL))
		{
			CString strMsg;
			strMsg.LoadString(IDS_FAIL_DROP_TEMP_TABLE);
			AfxMessageBox(strMsg);
		}
	}

	session.Release(); // Release session and commit.
	return TRUE;
}