// // TABLE LEVEL output of auditdb command. // ***Only one table and one file in the auditdb arguments can be specified*** // // It might throw the exception CeSqlException if fail in querying something from Ingres Database. // If you have the list of columns, then provide it !. // If the list of columns is null, then the function will query the list of columns ! // strTempTable [OUT]: receives the output of the temporary table name BOOL IJA_TableAuditdbOutput ( CaQueryTransactionInfo* pQueryInfo, CaTemporarySession* pSession, CString& strTempTable, CTypedPtrList<CObList, CaColumn*>* pListColumn, CString& strGranteeList) { CString strDatabase; CString strDatabaseOwner; CString strTable; CString strTableOwner; CString strStatement; CString strLocalIngresTemp = theApp.m_strLocalIITemporary; if (strLocalIngresTemp.IsEmpty()) return FALSE; #ifdef MAINWIN strLocalIngresTemp += _T("/"); #else strLocalIngresTemp += _T("\\"); #endif class CaLocalData { public: CaLocalData(BOOL bLocal):m_bLocal(bLocal), m_strFile(_T("")){} virtual ~CaLocalData() { while (!m_listObject.IsEmpty()) delete m_listObject.RemoveHead(); // // Prepare to delete the files (*.trl) outputed from AUDITDB: if (m_bLocal) { if (!m_strFile.IsEmpty() && (_taccess(m_strFile, 0) != -1)) DeleteFile (m_strFile); } }; BOOL m_bLocal; CString m_strFile; CTypedPtrList<CObList, CaColumn*> m_listObject; }; // // On the local node, do not use the remote command (RMCMD) BOOL bOnLocal = pSession->IsLocalNode(); CaLocalData localData(bOnLocal); BOOL bQueryColumns = pListColumn? FALSE: TRUE; if (bQueryColumns) { if (IJA_QueryColumn (pQueryInfo, localData.m_listObject)) pListColumn = &(localData.m_listObject); } CString csRmcmdOutPut; BOOL bResult = TRUE; ASSERT (pSession); if (!pSession) return FALSE; pQueryInfo->GetTable (strTable, strTableOwner); // // Get temp table name if (!GetTempAuditTableName(strTempTable, (LPCTSTR)strTable, (LPCTSTR)pQueryInfo->GetConnectedUser())) { // // Error while generating a temporary file name. CString strMsg; strMsg.LoadString(IDS_FAIL_TO_GENERATE_TEMPFILE); AfxMessageBox (strMsg); return FALSE; } // // Generate & Create the table to contain the audited table rows: // ------------------------------------------------------------- CString strSyntaxCreateTable; BOOL bCreate = RCRD_GenerateTemporaryTableSyntax((LPCTSTR)strTempTable, pListColumn, strSyntaxCreateTable, bOnLocal); if (!bCreate) { CString strMsg; strMsg.LoadString(IDS_FAIL_TO_GENERATE_TEMPTABLE); AfxMessageBox (strMsg); return FALSE; } CaLowlevelAddAlterDrop param (pQueryInfo->GetNode(), strDatabase, strSyntaxCreateTable); // // Create the temporary table in the current session: // -------------------------------------------------- param.NeedSession(FALSE); // // This function will throw exception if failed: bCreate = param.ExecuteStatement(NULL); if (!bOnLocal) { param.SetStatement(_T("commit")); // // This function will throw exception if failed: bCreate = param.ExecuteStatement(NULL); if (!strGranteeList.IsEmpty()) { CString csStatement; csStatement.Format("grant select on %s to %s",(LPCTSTR)strTempTable, (LPCTSTR) strGranteeList); param.SetStatement((LPCTSTR)csStatement); // This function will throw exception in case of failure bCreate = param.ExecuteStatement(NULL); param.SetStatement(_T("commit")); // This function will throw exception in case of failure bCreate = param.ExecuteStatement(NULL); } } // // Construct parameters for the need of generating AUDITDB Syntax: CString strFile; CStringList listFile; CTypedPtrList < CObList, CaIjaTable* > listTable; // // TODO: Construct the directory path on the local machine: // On remote machine the file name is generate by the utility adbtofst on NT machine // or used the pipe on unix machine see adbtofst if (!bOnLocal) { strFile = _T(""); } else { CString strAcceptedFileName = strTempTable; MakeFileName(strAcceptedFileName); strFile.Format (_T("%s%s.trl"), (LPCTSTR)strLocalIngresTemp, (LPCTSTR)strAcceptedFileName); } listFile.AddTail (strFile); listTable.AddTail (new CaIjaTable(strTable, strTableOwner)); localData.m_strFile = strFile; // // Generate AUDITDB syntax: BOOL bSyntax = FALSE; // FALSE generate syntax for the standard auditdb command // TRUE generate syntax for adbtofst if (!bOnLocal) bSyntax = TRUE; RCRD_GenerateAuditdbSyntax (pQueryInfo, listTable, listFile, strStatement, pQueryInfo->GetConnectedUser(),bSyntax); while (!listTable.IsEmpty()) delete listTable.RemoveHead(); if (bOnLocal) { CString strError = _T(""); // // Execute the AUDITDB command: bCreate = PROCESS_Execute (strStatement, strError); if (!bCreate) { if (!strError.IsEmpty()) AfxMessageBox (strError); return FALSE; } // // Check if the file has been successfuly created: if (_taccess(strFile, 0) == -1) { // // auditdb ...-file=<file name>, has failed to create file. CString strMsg; strMsg.LoadString(IDS_AUDITDB_FAILS_TO_CREATE_FILE); AfxMessageBox (strMsg); return FALSE; } // // Copy the binary data of audited table to the newly created Table: strStatement.Format ( _T("copy table session.%s () from '%s'"), (LPCTSTR)strTempTable, (LPCTSTR)strFile); param.SetStatement(strStatement); // // This function will throw exception if failed: param.ExecuteStatement(NULL); param.SetStatement(_T("commit")); // the table is temporary anyhow. need to commit because of potential "set session authorization" statements bCreate = param.ExecuteStatement(NULL); } else // // Execute ADBTOFST at the remote machine through RMCMD: { // // At this point, it requires that no sessions are opened ! pSession->Release(); //Generate adbtofst syntax CString AdbToFstSyntax; CString strDatabase; CString strDatabaseOwner; pQueryInfo->GetDatabase (strDatabase, strDatabaseOwner); AdbToFstSyntax.Format(_T("adbtofst -u%s %s %s %s"), (LPCTSTR)pQueryInfo->GetConnectedUser(), (LPCTSTR)strTempTable,(LPCTSTR)strDatabase, (LPCTSTR)strStatement); // // Execute the ADBTOFST command on the remote machine: bCreate = ExecRmcmdTestOutPut ((LPTSTR)(LPCTSTR)pQueryInfo->GetNode(), (LPTSTR)(LPCTSTR)AdbToFstSyntax,CMD_FASTLOAD,csRmcmdOutPut); if (!bCreate) { // // Error While executing the AdbToFst Command:\n\n%1 CString strMsg; if (csRmcmdOutPut.Find("E_DM1601_FLOAD_OPEN_DB")>=0) AfxFormatString1(strMsg, IDS_FAIL_TO_EXECUTE_ADBTOFST, (LPCTSTR)csRmcmdOutPut); else strMsg = csRmcmdOutPut; AfxMessageBox (strMsg); DropTempTable(pSession, (LPCTSTR)strTempTable, bOnLocal); return FALSE; } // // Reopen the previous session: pSession->Open(); if (!pSession->IsConnected()) { // // Failedto get Session. CString strMsg; strMsg.LoadString (IDS_FAIL_TO_GETSESSION); AfxMessageBox (strMsg); DropTempTable(pSession, (LPCTSTR)strTempTable, bOnLocal); return FALSE; } param.NeedSession(FALSE); } return TRUE; }
void CuDlgIjaTable::RefreshPaneTable(LPCTSTR lpszNode, LPCTSTR lpszDatabase, LPCTSTR lpszDatabaseOwner, LPCTSTR lpszTable, LPCTSTR lpszTableOwner) { CWaitCursor doWaitCursor; BOOL bCleanSession = FALSE; CString strOldNode = m_queryTransactionInfo.GetNode(); CString strOldDatabase; CString strOldDatabaseOwner; m_queryTransactionInfo.GetDatabase(strOldDatabase, strOldDatabaseOwner); if (!strOldNode.IsEmpty() && strOldNode.CompareNoCase(lpszNode)!=0) bCleanSession = TRUE; if (!strOldDatabase.IsEmpty() && strOldDatabase.CompareNoCase(lpszDatabase)!=0) bCleanSession = TRUE; if (bCleanSession) theApp.GetSessionManager().Cleanup(); m_queryTransactionInfo.SetNode (lpszNode); m_queryTransactionInfo.SetDatabase (lpszDatabase, lpszDatabaseOwner); m_queryTransactionInfo.SetTable (lpszTable, lpszTableOwner); m_bViewButtonClicked = FALSE; m_cButtonSelectAll.ShowWindow (SW_HIDE); m_cButtonRedo.ShowWindow (SW_HIDE); m_cButtonRecover.ShowWindow (SW_HIDE); m_cListCtrl.ShowWindow (SW_HIDE); CleanListCtrl(); SYSTEMTIME st; if (m_cDatePickerAfter.SendMessage (DTM_GETSYSTEMTIME, 0 , (LPARAM)&st) == GDT_VALID) { m_timeAfter = CTime(st); m_strAfter = toAuditdbInputDate(m_timeAfter); //m_timeAfter.Format (_T("%d-%m-%Y:%H:%M:%S")); } else m_strAfter = _T(""); if (m_cDatePickerBefore.SendMessage (DTM_GETSYSTEMTIME, 0 , (LPARAM)&st) == GDT_VALID) { m_timeBefore = CTime(st); m_strBefore = toAuditdbInputDate(m_timeBefore); //m_timeBefore.Format (_T("%d-%m-%Y:%H:%M:%S")); } else m_strBefore = _T(""); m_strAfter.MakeLower(); m_strBefore.MakeLower(); TRACE1 ("before: %s\n", m_strBefore); TRACE1 ("after : %s\n", m_strAfter); #if defined (SIMULATION) return; #endif // // Initialize the columns of the table as the list control header: while (!m_listColumn.IsEmpty()) delete m_listColumn.RemoveHead(); if (!IJA_QueryColumn (&m_queryTransactionInfo, m_listColumn)) { m_bColumnHeaderOK = FALSE; return; } m_bColumnHeaderOK = TRUE; LV_COLUMN lvcolumn; memset (&lvcolumn, 0, sizeof(lvcolumn)); lvcolumn.mask = LVCF_TEXT; while (m_cListCtrl.GetColumn (nHeader, &lvcolumn)) { // // Avoid looping for ever ! if (!m_cListCtrl.DeleteColumn(nHeader)) break; } BOOL bTextExtend = FALSE; CString strColum; SIZE size; CDC* pDC = m_cListCtrl.GetDC(); lvcolumn.mask = LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT|LVCF_WIDTH; m_nColumnHeaderCount = m_listColumn.GetCount(); int nCount = 0; CaColumn* pColumn = NULL; POSITION pos = m_listColumn.GetHeadPosition(); while (pos != NULL) { pColumn = m_listColumn.GetNext (pos); strColum = pColumn->GetName(); lvcolumn.fmt = pColumn->IsColumnText()? LVCFMT_LEFT: LVCFMT_RIGHT; lvcolumn.pszText = (LPTSTR)(LPCTSTR)strColum; lvcolumn.iSubItem = nHeader + nCount; bTextExtend = GetTextExtentPoint32 (pDC->m_hDC, strColum, strColum.GetLength(), &size); lvcolumn.cx = (bTextExtend && size.cx > 40)? size.cx+32: 40 +32; m_cListCtrl.InsertColumn (lvcolumn.iSubItem, &lvcolumn); nCount++; } #if defined (SORT_INDICATOR) CHeaderCtrl* pHdrCtrl= m_cListCtrl.GetHeaderCtrl(); if (pHdrCtrl) { int i, nHeaderCount = pHdrCtrl->GetItemCount(); pHdrCtrl->SetImageList(&m_ImageListOrder); HD_ITEM curItem; for (i=0; i<nHeaderCount; i++) { pHdrCtrl->GetItem(i, &curItem); curItem.mask= HDI_IMAGE | HDI_FORMAT; curItem.iImage= -1; curItem.fmt= HDF_LEFT | HDF_IMAGE | HDF_STRING /*|HDF_BITMAP_ON_RIGHT*/; pHdrCtrl->SetItem(i, &curItem); } } #endif // SORT_INDICATOR }