Esempio n. 1
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;
}
Esempio n. 2
0
void CuDlgIjaTable::DisplayMainTransaction()
{
	//
	// DIsplay Transactions:
	int idx, nCount = 0, nImage = 0;
	POSITION pos = m_listMainTrans.GetHeadPosition();
	while (pos !=  NULL)
	{
		CaTableTransactionItemData* pItem = m_listMainTrans.GetNext (pos);
		//
		// Check to see if this transaction matchs the filter
		// if not just skip it.
		if (!m_bAbortedTransaction && !pItem->GetCommit())
			continue; // Skip the rollback transaction

		if (!m_bCommittedTransaction && pItem->GetCommit())
			continue; // Skip the commit transaction
		
		if (m_strUser.CompareNoCase(theApp.m_strAllUser) != 0 && m_strUser.CompareNoCase (pItem->GetUser()) != 0)
			continue;

		nCount = m_cListCtrl.GetItemCount();
		nImage = pItem->GetImageId();

		idx = m_cListCtrl.InsertItem (nCount, _T(""), nImage);
		if (idx != -1)
		{
			switch (pItem->GetAction())
			{
			case T_DELETE:
				IJA_ColorItem(&m_cListCtrl, idx, theApp.m_property.TRGB_DELETE());
				break;
			case T_INSERT:
				IJA_ColorItem(&m_cListCtrl, idx, theApp.m_property.TRGB_INSERT());
				break;
			case T_BEFOREUPDATE:
				IJA_ColorItem(&m_cListCtrl, idx, theApp.m_property.TRGB_BEFOREUPDATE());
				break;
			case T_AFTERUPDATE:
				IJA_ColorItem(&m_cListCtrl, idx, theApp.m_property.TRGB_AFTEREUPDATE());
				break;
			case T_CREATETABLE:
			case T_ALTERTABLE:
			case T_DROPTABLE:
			case T_RELOCATE:
			case T_MODIFY:
			case T_INDEX:
				IJA_ColorItem(&m_cListCtrl, idx, theApp.m_property.TRGB_OTHERS());
				break;
			default:
				break;
			}
			m_cListCtrl.SetItemData (idx, (DWORD)pItem);

			m_cListCtrl.SetItemText (idx, 0, pItem->GetStrTransactionID());
			m_cListCtrl.SetItemText (idx, 1, pItem->GetLsn());
			m_cListCtrl.SetItemText (idx, 2, pItem->GetDateLocale());
			m_cListCtrl.SetItemText (idx, 3, pItem->GetUser());
			m_cListCtrl.SetItemText (idx, 4, pItem->GetStrOperation());
#if defined (SIMULATION)
			m_cListCtrl.SetItemText (idx, 5, pItem->GetName());
#else
			//
			// Display the real data:
			CStringList& listdata = pItem->GetListData();
			POSITION p = listdata.GetHeadPosition();
			int nCounter = 0;
			while (p != NULL && nCounter < m_nColumnHeaderCount)
			{
				CString strItem = listdata.GetNext (p);
				m_cListCtrl.SetItemText (idx, nHeader + nCounter, strItem);

				nCounter++;
			}
#endif
		}
	}
}