/////////////////////////////////////////////////////////////////////// // HRESULT CTableCopy::CopyTables // /////////////////////////////////////////////////////////////////////// HRESULT CTableCopy::CopyTables() { HRESULT hr = S_OK; DBCOUNTITEM cRowsCopied = 0; // Create the Table (if desired) if(m_fCopyTables) QTESTC(hr = m_pCToTable->CreateTable()); // Create the indexes (if desired) if(m_fCopyIndexes) QTESTC(hr = m_pCToTable->CopyIndexes(m_pCFromTable)); //GetColInfo for TargetTable QTESTC(hr = m_pCToTable->GetColInfo(m_dwInsertOpt)); //Now Copy the Data QTESTC(hr = m_pCToTable->CopyData(m_pCFromTable, &cRowsCopied)); CLEANUP: //Display Results if(SUCCEEDED(hr)) wMessageBox(NULL, MB_TASKMODAL | MB_ICONINFORMATION | MB_OK, wsz_SUCCESS, wsz_COPY_SUCCESS, cRowsCopied); else wMessageBox(NULL, MB_TASKMODAL | MB_ICONEXCLAMATION | MB_OK, wsz_ERROR, wsz_COPY_FAILURE); return hr; }
//////////////////////////////////////////////////////////////////////// // HRESULT DisplayErrorRecords // ///////////////////////////////////////////////////////////////////////////// HRESULT DisplayErrorRecords(HWND hWnd, ULONG cRecords, IErrorRecords* pIErrorRecords, WCHAR* pwszFile, ULONG ulLine) { HRESULT hr = S_OK; IErrorInfo* pIErrorInfo = NULL; BSTR bstrErrorInfo = NULL; BSTR bstrSQLInfo = NULL; LCID lcid = GetSystemDefaultLCID(); //Get the Error Records if(cRecords && pIErrorRecords) { LONG lNativeError = 0; ERRORINFO ErrorInfo; //Loop through the records for(ULONG i=0; i<cRecords; i++) { //GetErrorInfo XTESTC(hr = pIErrorRecords->GetErrorInfo(i,lcid,&pIErrorInfo)); //Get the Description XTESTC(hr = pIErrorInfo->GetDescription(&bstrErrorInfo)); //Get the Basic ErrorInfo XTESTC(hr = pIErrorRecords->GetBasicErrorInfo(i,&ErrorInfo)); //Get the SQL Info GetSqlErrorInfo(i, pIErrorRecords, &bstrSQLInfo); //Display the Error if(bstrSQLInfo) wMessageBox(hWnd, (hWnd ? MB_APPLMODAL : MB_TASKMODAL) | MB_ICONEXCLAMATION | MB_OK, wsz_ERRORINFO, L"Interface: %s\nResult: %x = %s\n\nIErrorInfo: [%s] %s\n\nFile: %s\nLine: %d", GetInterfaceName(ErrorInfo.iid), ErrorInfo.hrError, GetErrorName(ErrorInfo.hrError), bstrSQLInfo, bstrErrorInfo, pwszFile, ulLine); else wMessageBox(hWnd, (hWnd ? MB_APPLMODAL : MB_TASKMODAL) | MB_ICONEXCLAMATION | MB_OK, wsz_ERRORINFO, L"Interface: %s\nResult: %x = %s\n\nIErrorInfo: %s\n\nFile: %s\nLine: %d", GetInterfaceName(ErrorInfo.iid), ErrorInfo.hrError, GetErrorName(ErrorInfo.hrError), bstrErrorInfo, pwszFile, ulLine); SAFE_RELEASE(pIErrorInfo); SAFE_SYSFREE(bstrErrorInfo); SAFE_SYSFREE(bstrSQLInfo); } } CLEANUP: SAFE_RELEASE(pIErrorInfo); SAFE_SYSFREE(bstrErrorInfo); SAFE_SYSFREE(bstrSQLInfo); return hr; }
//////////////////////////////////////////////////////////////////// // BOOL CProgress::Update // //////////////////////////////////////////////////////////////////// BOOL CProgress::Update(WCHAR* pwszText) { ASSERT(pwszText); //Update the progress text SetText(pwszText); // Now check for a cancel from the user, by checking // the messages from the user if(Cancel()) { if(IDYES == wMessageBox(m_hWnd, MB_TASKMODAL | MB_ICONEXCLAMATION | MB_YESNO, wsz_CANCEL, wsz_CANCEL_OP)) { //Indicate the users wishes to stop return FALSE; } else { m_fCancel = FALSE; } } //Indicate the user wishes to continue return TRUE; }
///////////////////////////////////////////////////////////////////////////// // BOOL CS3Dialog::Connect // ///////////////////////////////////////////////////////////////////////////// BOOL CS3Dialog::Connect(CDataSource* pCDataSource) { CDataSource *pCToDataSource = m_pCTableCopy->m_pCToTable->m_pCDataSource; CDataSource *pCFromDataSource = m_pCTableCopy->m_pCFromTable->m_pCDataSource; BOOL fReturn = FALSE; //Connect to the DataSource HRESULT hr = m_pCTableCopy->m_pCToTable->Connect(m_hWnd, pCDataSource); //If Connected if SUCCEEDED(hr) { // Verify we can use this data source // Just give a warning to the user, since the DataSource may actually // be updatable, but it is returning the wrong property value. if(pCToDataSource->m_fReadOnly) { wMessageBox(m_hWnd, MB_TASKMODAL | MB_ICONEXCLAMATION | MB_OK, wsz_WARNING, wsz_READONLY_DATASOURCE_, pCToDataSource->m_pwszDataSource); } //See if this is a similar DSN than the Source //If DSN's are not similar, then we need to translate m_pCTableCopy->m_fTranslate = !pCToDataSource->IsSimilar(pCFromDataSource); fReturn = TRUE; } return TRUE; }
///////////////////////////////////////////////////////////////////////////// // HRESULT CMallocSpy::DumpLeaks // ///////////////////////////////////////////////////////////////////////////// HRESULT CMallocSpy::DumpLeaks() { ULONG cTotalLeaks = 0; SIZE_T cTotalBytes = 0; DWORD dwSelection = IDOK; //Display Leaks to the Output Window while(!CAllocList.IsEmpty()) { //Obtain the pointer to the leaked memory void* pRequest = CAllocList.RemoveHead(); ASSERT(pRequest); void* pActual = HEADER_OFFSET(pRequest); ASSERT(pActual); //Make sure that the head/tail signitures are intact if(HEAD_SIGNITURE(pActual) != HEADSIGN) InternalTraceFmt(L"TRACE - IMallocSpy HeadSigniture Corrupted! - 0x%p, ID=%08lu, %Iu byte(s)\n", pRequest, BUFFER_ID(pActual), BUFFER_LENGTH(pActual)); if(TAIL_SIGNITURE(pActual) != TAILSIGN) InternalTraceFmt(L"TRACE - IMallocSpy TailSigniture Corrupted! - 0x%p, ID=%08lu, %Iu byte(s)\n", pRequest, BUFFER_ID(pActual), BUFFER_LENGTH(pActual)); SIZE_T ulSize = BUFFER_LENGTH(pActual); ULONG ulID = BUFFER_ID(pActual); WCHAR* pwszFileName= BUFFER_FILENAME(pActual); ULONG ulLine = BUFFER_LINENUMBER(pActual); //Display a message box for all leaks (until the user is tired of it...) if(dwSelection == IDOK) { dwSelection = wMessageBox(GetFocus(), MB_TASKMODAL | MB_ICONWARNING | MB_OKCANCEL | MB_DEFBUTTON1, L"IMallocSpy Leak", L"IMallocSpy Leak:\n" L"0x%p, ID=%08lu, %Iu byte(s), File: %s, Line %d\n\n", pRequest, ulID, ulSize, pwszFileName, ulLine); } //Include FileName and Line Number of the leak... InternalTraceFmt(L"-- IMallocSpy Leak! - 0x%p,\tID=%08lu,\t%Iu byte(s),\tFile: %s,\tLine %d" wWndEOL, pRequest, ulID, ulSize, pwszFileName, ulLine); cTotalLeaks++; cTotalBytes += ulSize; //Free the Leak //You really cant free the leak since the app could be potentially still //using it. Or the DLL may still be in use or have attached threads... //SAFE_FREE(pActual); } if(cTotalLeaks) InternalTraceFmt(L"-- IMallocSpy Total Leaks: %lu = %Iu byte(s)" wWndEOL, cTotalLeaks, cTotalBytes); return S_OK; }
///////////////////////////////////////////////////////////////////////////// // CAggregate::HandleAggregation // ///////////////////////////////////////////////////////////////////////////// HRESULT CAggregate::HandleAggregation(REFIID riid, IUnknown** ppIUnknown) { HRESULT hr = S_OK; IUnknown* pIUnkInner = ppIUnknown ? *ppIUnknown : NULL; if(pIUnkInner) { //This would be a bug in the provider if aggregaiton succeeded //but the user didn't request IID_IUnknown. if(riid != IID_IUnknown) { //NOTE: We don't want to just continue here since this is dangerous. //If the provider succeeds, this means the outer object was probably returned rather //than the inner non-delegating IUnknown, this will cause our outer controlling object //to have a circular QI problem when asked for an inner interface, and will have refcounting //problems as well. Might as well let the use know, and don't further this provider bug... if(IDNO == wMessageBox ( GetFocus(), MB_TASKMODAL | MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON1, wsz_ERROR, L"Provider Bug: Allowed Aggregation and riid!=IID_IUnknown!\n\n" L"This may crash your Provider...\n" L"Do you wish to continue anyway?" )) { //return a failure if the user wished not to continue... TESTC(hr = E_INVALIDARG); } } //We need to "hook" up our objects. So that our outer controlling object //has a pointer to the inner for delegating QI calls. This must be an non-delegating //inner IUnknown, (see below). Also the caller of this function will ALWAYS //release their CAggregate object, and we return a the Aggregate object with our //reference count. (consistent with COM, calle never releases callers IUnknown, and //calle always addref's if they hold onto the callers object). if(SUCCEEDED(hr = SetInner(pIUnkInner))) { //SetInner TRACE_RELEASE(pIUnkInner, L"IUnknown"); hr = QueryInterface(IID_IUnknown, (void**)ppIUnknown); } } CLEANUP: return hr; }
void Log::fatal(std::string domain, std::string msg) { std::string str = ts() + "Fatal [" + domain + "] - " + chomp(msg); if (inPythonScript) { PyErr_SetString(PyExc_RuntimeError, str.c_str()); } else { std::cerr << str << std::endl; #ifdef _WIN32 wMessageBox("Tsunagari - Fatal", str); #endif #ifdef __APPLE__ macMessageBox("Tsunagari - Fatal", str.c_str()); #endif } }
///////////////////////////////////////////////////////////////// // HRESULT CTableCopy::MapTypes // ///////////////////////////////////////////////////////////////// HRESULT CTableCopy::MapTypes() { HRESULT hr = S_OK; //Now get the TypeInfo for all columns //IDBSchemaRowsets may not be supported, which we may be able to do without //on the source table, we are going to lose IsNullable, IsAutoInc and other options hr = m_pCFromTable->GetTypeInfo(); //Now map all the Types correctly from the Source to the Target QTESTC(hr = m_pCToTable->MapTableInfo(m_pCFromTable)); CLEANUP: if(FAILED(hr)) wMessageBox(NULL, MB_TASKMODAL | MB_ICONEXCLAMATION | MB_OK, wsz_ERROR, wsz_TYPEMAPPING_FAILURE); return hr; }
void Log::err(std::string domain, std::string msg) { if (conf.halting == HALT_ERROR) { Log::fatal(domain, msg); exit(1); } std::string str = ts() + "Error [" + domain + "] - " + chomp(msg); if (inPythonScript) { PyErr_SetString(PyExc_RuntimeError, str.c_str()); } else { if (verb > V_QUIET) { std::cerr << str << std::endl; #ifdef _WIN32 wMessageBox("Tsunagari - Error", str); #endif #ifdef __APPLE__ macMessageBox("Tsunagari - Error", str.c_str()); #endif } } }
//////////////////////////////////////////////////////////////////////// // HRESULT DisplayAllErrors // ///////////////////////////////////////////////////////////////////////////// HRESULT DisplayAllErrors(HWND hWnd, HRESULT Actualhr, WCHAR* pwszFile, ULONG ulLine) { HRESULT hr = S_OK; ULONG cRecords = 0; IErrorRecords* pIErrorRecords = NULL; //Try to display Extened ErrorInfo if((hr = GetErrorRecords(&cRecords, &pIErrorRecords))==S_OK) { hr = DisplayErrorRecords(hWnd, cRecords, pIErrorRecords, pwszFile, ulLine); } //If not available, display MSG Box with info else { //display the Error wMessageBox(hWnd, (hWnd ? MB_APPLMODAL : MB_TASKMODAL) | MB_ICONEXCLAMATION | MB_OK, wsz_ERRORINFO, L"Interface: %s\nResult: %x = %s\n\nIErrorInfo: %s\n\nFile: %s\nLine: %d", L"Unknown", Actualhr, GetErrorName(Actualhr), L"Error Object not available", pwszFile, ulLine); } SAFE_RELEASE(pIErrorRecords); return hr; }
///////////////////////////////////////////////////////////////////// // CS3Dialog::DlgProc // ///////////////////////////////////////////////////////////////////// BOOL WINAPI CS3Dialog::DlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { static WCHAR wszBuffer[MAX_NAME_LEN+1]; switch(msg) { case WM_INITDIALOG: { Busy(); //Store the "this" pointer, since this is a static method CS3Dialog* pThis = (CS3Dialog*)lParam; SetWindowLongPtrA(hWnd, GWLP_USERDATA, (LONG_PTR)pThis); //On INIT we know we have a valid hWnd to store CenterDialog(hWnd); pThis->m_hWnd = hWnd; //Init all controls to the default values pThis->InitControls(); //Limit the length of User Entered TableName SendDlgItemMessage(hWnd, IDE_TO_TABLE, EM_LIMITTEXT, (WPARAM)MAX_NAME_LEN-1, 0L); pThis->RefreshControls(); pThis->m_pCTableCopy->m_pCWizard->DestroyPrevStep(WIZ_STEP3); return HANDLED_MSG; } case WM_COMMAND: { //Obtain the "this" pointer CS3Dialog* pThis = (CS3Dialog*)GetWindowLongPtrA(hWnd, GWLP_USERDATA); CTable *pCFromTable = pThis->m_pCTableCopy->m_pCFromTable; CTable *pCToTable = pThis->m_pCTableCopy->m_pCToTable; CDataSource *pCToDataSource = pCToTable->m_pCDataSource; CDataSource *pCFromDataSource = pCFromTable->m_pCDataSource; // All buttons are handled the same way switch(GET_WM_COMMAND_ID(wParam, lParam)) { case IDB_TO_CONNECT: { //kill implicit connection pCToDataSource->Disconnect(); //on connect get whatever is now listed in the drop down LRESULT iSel = 0; if((iSel = SendMessage(GetDlgItem(pThis->m_hWnd, IDC_PROVIDER_NAME), CB_GETCURSEL, 0, 0L)) != CB_ERR) { //Since we have the CBS_SORT turned on, the order in the Combo Box does //not match our array, so we pass the array index (lParam) as the item data LRESULT lParam = SendMessage(GetDlgItem(pThis->m_hWnd, IDC_PROVIDER_NAME), CB_GETITEMDATA, iSel, 0L); pCFromTable->m_pCDataSource->m_pwszProviderName = pCFromDataSource->m_rgProviderInfo[lParam].wszName; /* if((lParam < (LONG)pCToDataSource->m_cProviderInfo) && (wcscmp(pCFromDataSource->m_rgProviderInfo[lParam].wszName, pCFromDataSource->m_pwszProviderName)!=0)) { //Clear Table/Column List Views SendMessage(GetDlgItem(hWnd, IDL_TABLES), TVM_DELETEITEM, (WPARAM)0, (LPARAM)TVI_ROOT); SendMessage(GetDlgItem(hWnd, IDL_COLUMNS), LVM_DELETEALLITEMS, (WPARAM)0, (LPARAM)0); //Clear Table info memset(&pCToTable->m_TableInfo, 0, sizeof(TABLEINFO)); pCToTable->m_wszQualTableName[0] = EOL; //Disconnect from the DataSource and Update controls pCToTable->m_pCDataSource->Disconnect(); } */ } else { //The user must have typed in a Provider Name directly //This may not map to a provider in the list, so assume the name is a ProgID/CLSID wSendMessage(GetDlgItem(pThis->m_hWnd, IDC_PROVIDER_NAME), WM_GETTEXT, MAX_NAME_LEN, wszBuffer); pCToTable->m_pCDataSource->m_pwszProviderName = wszBuffer; } Busy(); if(pThis->Connect()) { Busy(); pThis->RefreshControls(); SetFocus(GetDlgItem(hWnd, IDE_TO_TABLE)); SendMessage(GetDlgItem(hWnd, IDE_TO_TABLE), EM_SETSEL, 0, -1); //Highlight TableName } return HANDLED_MSG; } case IDOK: { //Get the TableName Busy(); wSendMessage(GetDlgItem(hWnd, IDE_TO_TABLE), WM_GETTEXT, MAX_NAME_LEN-1, pCToTable->m_TableInfo.wszTableName); //If the TableNames are the same (ignoring case) and the //DataSource is the same then the copy is worthless (a no-op) if(_wcsicmp(pCToTable->m_TableInfo.wszTableName, pCFromTable->m_TableInfo.wszTableName)==0 && pCToDataSource->IsEqual(pCFromDataSource)) { //Need to enter a different table name from the source wMessageBox(hWnd, MB_TASKMODAL | MB_ICONEXCLAMATION | MB_OK, wsz_ERROR, wsz_SAME_TABLE_NAME, pCToDataSource->m_pwszTableTerm); SetFocus(GetDlgItem(hWnd, IDE_TO_TABLE)); SendMessage(GetDlgItem(hWnd, IDE_TO_TABLE), EM_SETSEL, 0, -1); //Highlight TableName return HANDLED_MSG; } StringCchCopyW(pCToTable->m_wszQualTableName, sizeof(pCToTable->m_wszQualTableName)/sizeof(WCHAR), pCToTable->m_TableInfo.wszTableName); pThis->m_pCTableCopy->m_pCWizard->DisplayStep(WIZ_STEP4); return HANDLED_MSG; } case IDB_PREV: //Get the TableName Busy(); wSendMessage(GetDlgItem(hWnd, IDE_TO_TABLE), WM_GETTEXT, MAX_NAME_LEN-1, pCToTable->m_TableInfo.wszTableName); StringCchCopyW(pCToTable->m_wszQualTableName, sizeof(pCToTable->m_wszQualTableName)/sizeof(WCHAR), pCToTable->m_TableInfo.wszTableName); pThis->m_pCTableCopy->m_pCWizard->DisplayStep(WIZ_STEP2); return HANDLED_MSG; case IDCANCEL: Busy(); EndDialog(hWnd, GET_WM_COMMAND_ID(wParam, lParam)); return HANDLED_MSG; } // Now look for notification messages switch(GET_WM_COMMAND_CMD(wParam, lParam)) { case LBN_SELCHANGE: { /* //A Provider Change requires a refresh if(IDC_PROVIDER_NAME == GET_WM_COMMAND_ID(wParam, lParam)) { //Get new selection Busy(); LONG iSel = 0; if((iSel = SendMessage(GetDlgItem(pThis->m_hWnd, IDC_PROVIDER_NAME), CB_GETCURSEL, 0, 0L)) != CB_ERR) { //Since we have the CBS_SORT turned on, the order in the Combo Box does //not match our array, so we pass the array index (lParam) as the item data LONG lParam = SendMessage(GetDlgItem(pThis->m_hWnd, IDC_PROVIDER_NAME), CB_GETITEMDATA, iSel, 0L); if((lParam < (LONG)pCToDataSource->m_cProviderInfo) && (wcscmp(pCToDataSource->m_rgProviderInfo[lParam].wszName, pCToDataSource->m_pwszProviderName)!=0)) { pCToDataSource->Disconnect(); } } } pThis->RefreshControls(); */ } case EN_CHANGE: { pThis->EnableTable(); return HANDLED_MSG; } } } } return UNHANDLED_MSG; }