Exemplo n.º 1
0
void CADO::dump_com_error(_com_error &e)
{
	_bstr_t bstrSource(e.Source());
	_bstr_t bstrDescription(e.Description());
	g_logger.error("ADO Error Code = %08lx Code meaning = %s Source = %s Description = %s",
		e.Error(), e.ErrorMessage(), (LPCTSTR)bstrSource, (LPCTSTR)bstrDescription);
}
Exemplo n.º 2
0
BOOL CADODatabase::Open(LPCTSTR lpstrConnection, LPCTSTR lpstrUserID, LPCTSTR lpstrPassword)
{
	HRESULT hr = S_OK;

	if(IsOpen())
		Close();

	if(_tcscmp(lpstrConnection, _T("")) != 0)
		m_strConnection = lpstrConnection;

	ASSERT(!m_strConnection.IsEmpty());

	try
	{
		if(m_nConnectionTimeout != 0)
			m_pConnection->PutConnectionTimeout(m_nConnectionTimeout);
		hr = m_pConnection->Open(_bstr_t(m_strConnection), _bstr_t(lpstrUserID), _bstr_t(lpstrPassword), NULL);
		return hr == S_OK;
	}
	catch(_com_error &e)
	{
	//	dump_com_error(e);
		CString ErrorStr ;
		_bstr_t bstrSource(e.Source());
		_bstr_t bstrDescription(e.Description());
		ErrorStr.Format( _T("CADORecordset Error\n\tCode = %08lx\n\tCode meaning = %s\n\tSource = %s\n\tDescription = %s\n"),
			e.Error(), e.ErrorMessage(), (LPCSTR)bstrSource, (LPCSTR)bstrDescription );
		g_log.Trace(LOGL_HIG , LOGC_ERROR , __TFILE__ , __LINE__ , _T("数据库连接错误:%s") ,bstrDescription) ;
		return FALSE;
	}
	
}
Exemplo n.º 3
0
/// \see http://stackoverflow.com/questions/324974/in-wia-how-can-i-add-my-program-in-the-program-list-of-acquiring-images-from-a
void App::RegisterWIAHandler(bool bRegister)
{
   CComPtr<IWiaDevMgr> spWiaDevMgr;
   HRESULT hr = spWiaDevMgr.CoCreateInstance(CLSID_WiaDevMgr,
      NULL,
      CLSCTX_LOCAL_SERVER);

   if (FAILED(hr))
      return;

   CComBSTR bstrCommandline(_T("\"") + Path::ModuleFilename() + _T("\" --open-wia \"%1\" \"%2\""));
   CComBSTR bstrName(CString(MAKEINTRESOURCE(IDR_MAINFRAME)));
   CComBSTR bstrDescription(CString(MAKEINTRESOURCE(IDR_WIA_DESC)));
   CComBSTR bstrIcon(Path::ModuleFilename() + _T(",0"));

   hr = spWiaDevMgr->RegisterEventCallbackProgram(
      bRegister ? WIA_REGISTER_EVENT_CALLBACK : WIA_UNREGISTER_EVENT_CALLBACK,
      NULL,
      &WIA_EVENT_DEVICE_CONNECTED,
      bstrCommandline,
      bstrName,
      bstrDescription,
      bstrIcon);

   // when this fails, the user isn't an elevated user
   if (FAILED(hr))
      AtlMessageBox(NULL, _T("Error registering/unregisterin WIA event! Are you administrator?"), IDR_MAINFRAME, MB_OK);
}
static 	void dump_com_error(_com_error &e)
{
	::AtlTrace("Error\n");
	//TRACE1("\a\tCode = %08lx\n", e.Error());
	//TRACE1("\a\tCode meaning = %s", e.ErrorMessage());
	_bstr_t bstrSource(e.Source());
	_bstr_t bstrDescription(e.Description());
	::AtlTrace("\a\tSource = %s\n", (LPCSTR) bstrSource);
	::AtlTrace("\a\tDescription = %s\n", (LPCSTR) bstrDescription);
}
Exemplo n.º 5
0
void dump_com_error(_com_error &e)
{
    _tprintf(_T("Oops - hit an error!\n"));
    _tprintf(_T("\a\tCode = %08lx\n"), e.Error());
    _tprintf(_T("\a\tCode meaning = %s\n"), e.ErrorMessage());
    _bstr_t bstrSource(e.Source());
    _bstr_t bstrDescription(e.Description());
    _tprintf(_T("\a\tSource = %s\n"), (LPCTSTR) bstrSource);
    _tprintf(_T("\a\tDescription = %s\n"), (LPCTSTR) bstrDescription);
}
Exemplo n.º 6
0
void DbError(_com_error &e)
{
	_bstr_t bstrSource(e.Source());
	_bstr_t bstrDescription(e.Description());
      
	CUString msg;
	msg.Format("\n\tSource :  %s \n\tdescription : %s \n ",(LPCSTR)bstrSource,(LPCSTR)bstrDescription);

	MessageBox(NULL, msg, "", MB_OK);
}
Exemplo n.º 7
0
void ComErrorMsg(HWND hWnd, _com_error &e)
{
	_bstr_t bstrSource(e.Source());
	_bstr_t bstrMessage(e.ErrorMessage());
	_bstr_t bstrDescription(e.Description());

	CString msg;
	msg.Format("\n\tSource :  %s \n\tMessage : %s\n\tdescription : %s \n ", (LPCSTR)bstrSource, (LPCSTR)bstrMessage, (LPCSTR)bstrDescription);

	MessageBox(hWnd, msg, "LXWebSite", MB_OK);
}
Exemplo n.º 8
0
void dump_com_error(_com_error &e)
{ 
	CString strError;

	_bstr_t bstrSource(e.Source());
	_bstr_t bstrDescription(e.Description());
	// Print Com errors. 
	strError.Format(_T("Database Engine Error\n\nCode  %08lx\nmean:%s\nSource: %s\nDescription: %s\n"),
		e.Error(), e.ErrorMessage(), (LPTSTR) bstrSource, (LPTSTR) bstrDescription);
	AfxMessageBox(strError,MB_OK+MB_ICONERROR); 
}
void CThingTreeCtrl::OnReloadModule() 
{
	// FireReLoadModule();
	HTREEITEM hSelected;
	CString	strModuleName;
	IModule *pModule = NULL;
	HRESULT hr = S_OK;

	if (!m_pWorld)
		return;

	hSelected = m_treeCtrl.GetNextItem(m_hModules, TVGN_CARET);

	if (!hSelected)
		return;

	// get the module name from the tree
	strModuleName = m_treeCtrl.GetItemText(hSelected);

	// get the module from the world
	if (FAILED(hr = m_pWorld->get_Module(CComBSTR(strModuleName), &pModule)))
		goto exit;

	// call reload on the module
	if (FAILED(hr = pModule->Reload(VARIANT_TRUE)))
	{
		CComBSTR bstrDescription("Error reloading module.");
		CComPtr<IErrorInfo> pErrorInfo;
		CString strError;
		CString strTitle;
		CString strInfo;

		strTitle.LoadString(IDS_RELOAD_MODULE);
		strInfo.LoadString(IDS_ERROR_MODULE_RELOAD);

		::GetErrorInfo(0L, &pErrorInfo);

		// we possibly could have no errorinfo from server-side/sync method,
		// if HRESULT isn't in the IThing range (the ReportThingError above will format
		// error strings in the proper range)
		if (pErrorInfo)
		{
			//pErrorInfo->GetSource(&bstrSource.m_str);
			pErrorInfo->GetDescription(&bstrDescription.m_str);
		}
		strError = strInfo + CString(bstrDescription);

		MessageBox(strError, strTitle, MB_ICONERROR);
	}


exit:
	SAFERELEASE(pModule);
}
Exemplo n.º 10
0
// ErrCom Function
void ErrCom(_com_error &e)
{
	_bstr_t bstrSource(e.Source());
	_bstr_t bstrDescription(e.Description());
	
	// Print Com errors.  
	printf("Error\n");
	printf("\tCode = %08lx\n", e.Error());
	printf("\tCode meaning = %s\n", e.ErrorMessage());
	printf("\tSource = %s\n", (LPCSTR) bstrSource);
	printf("\tDescription = %s\n", (LPCSTR) bstrDescription);
}
Exemplo n.º 11
0
void PrintComError(_com_error &e)
{
	_bstr_t bstrSource(e.Source());
	_bstr_t bstrDescription(e.Description());

	// Print COM errors. 
	PTRACE(1, "catch _com_error:\tError = " << e.Error()
		<< "\tErrorMessage = " << (const char*)e.ErrorMessage()
		<< "\tSource = " << (const char*)bstrSource
		<< "\tDescription = " << (const char*)bstrDescription
		);
}
Exemplo n.º 12
0
bool ADOConn::GetSQLFile(char *tablename,char *itemname,CFile *pFile)
{
	_RecordsetPtr pRs = NULL;
    _ConnectionPtr pConnection = NULL;	
    _variant_t varChunk;	
    HRESULT hr;	
    VARIANT varBLOB;	
    //_bstr_t strCnn("Provider=SQLOLEDB.1;Integrated Security=SSPI;
	//Persist Security Info=False;Initial Catalog=CUSTOM;Data Source=SERVER");    	
    try		
    {	
        //Open a connection	
        pConnection.CreateInstance(__uuidof(Connection));		
        hr = pConnection->Open((_bstr_t)m_strConn,"sa","123",adModeUnknown);        		
        pRs.CreateInstance(__uuidof(Recordset));		
        pRs->Open("select *from test where name='content'",_variant_t((IDispatch *) pConnection,true),adOpenKeyset,adLockOptimistic,adCmdText);		
		//read  data  	
		long lDataLength = pRs->Fields->GetItem(itemname)->ActualSize;	
		varBLOB = pRs->GetFields()->GetItem(itemname)->GetChunk(lDataLength+1);		
		if(varBLOB.vt == (VT_ARRAY | VT_UI1))        			
		{
			byte *pBuf = NULL;   			
            pBuf = (byte*)GlobalAlloc(GMEM_FIXED,lDataLength+1);			
            SafeArrayAccessData(varBLOB.parray,(void **)pBuf); 			
            //Build a File in Windows Temp Directory			
//             char tmpPath[_MAX_PATH+1];			
//             GetTempPath(_MAX_PATH,tmpPath);			
//             CString strFileName = "temp.bmp";
// 			pFile->
//             strFileName = tmpPath+strFileName;									
//             CFile outFile(strFileName,CFile::modeCreate|CFile::modeWrite);			
			LPSTR buffer = (LPSTR)GlobalLock((HGLOBAL)pBuf);			
            pFile->WriteHuge(buffer,lDataLength);		
            GlobalUnlock((HGLOBAL)pBuf);		
          pFile->Close();           		
            SafeArrayUnaccessData (varBLOB.parray);		
		}		
        pRs->Close();		
        pConnection->Close();		
	}
	catch(_com_error &e)
	{
			// Notify the user of errors if any.	
		_bstr_t bstrSource(e.Source());	
		_bstr_t bstrDescription(e.Description());	
		CString sError;	
		sError.Format("Source : %s \n Description : %s\n",(LPCSTR)bstrSource,(LPCSTR)bstrDescription);	
		AfxMessageBox(sError);   
		return false;
	}
	return true;
}
Exemplo n.º 13
0
//打印调用ADO控件时产生的详细错误信息
void LoadManage::dump_com_error(_com_error &e)
{
	CString ErrorStr;
	_bstr_t bstrSource(e.Source());
	_bstr_t bstrDescription(e.Description());
	ErrorStr.Format( "/n/tADO Error/n/tCode = %08lx/n/tCode meaning = %s/n/tSource = %s/n/tDescription = %s/n/n",
		e.Error(), e.ErrorMessage(), (LPCTSTR)bstrSource, (LPCTSTR)bstrDescription );
	//在调试窗口中打印错误信息,在Release版中可用DBGView查看错误信息
	::OutputDebugString((LPCTSTR)ErrorStr);
#ifdef _DEBUG
	AfxMessageBox(ErrorStr, MB_OK | MB_ICONERROR);
#endif	
}
Exemplo n.º 14
0
void read(std::string excelFile, int sheetIndex, bool header, std::string csvFile)
{
    clock_t t1 = clock();

    std::cout << "reading " << excelFile;

    if(FAILED(::CoInitialize(NULL))) return;

    _RecordsetPtr pSchema = NULL;
    _RecordsetPtr pRec = NULL;

    int cellCount = 0;

    try
    {
        _bstr_t connStr(makeConnStr(excelFile, header).c_str());

        TESTHR(pRec.CreateInstance(__uuidof(Recordset)));
        TESTHR(pRec->Open(sqlSelectSheet(connStr, sheetIndex).c_str(), connStr, adOpenStatic, adLockOptimistic, adCmdText));

        std::ofstream stream(csvFile.c_str());

        while(!pRec->adoEOF)
        {
            for(long i = 0; i < pRec->Fields->GetCount(); ++i)
            {
                if(i > 0) stream << ";";
                _variant_t v = pRec->Fields->GetItem(i)->Value;
                if(v.vt == VT_R8)
                    stream << v.dblVal;
                if(v.vt == VT_BSTR)
                    stream << (char*)(_bstr_t)v.bstrVal;
                ++cellCount;
            }
            stream << std::endl;
            pRec->MoveNext();
        }
    }
    catch(_com_error &e)
    {
        _bstr_t bstrDescription(e.Description());
        CharToOem(bstrDescription, bstrDescription);
        std::cout << bstrDescription << std::endl;
    }

    ::CoUninitialize();

    clock_t t2 = clock();
    double t = (double)(t2 - t1) / CLOCKS_PER_SEC;
    std::cout << ": " << t << " sec; " << cellCount / t << " cells/sec" << "; see " << csvFile << std::endl;
}
Exemplo n.º 15
0
BOOL CLoginDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	this->GetDlgItem(IDOK)->ShowWindow(FALSE);
	this->GetDlgItem(IDCANCEL)->ShowWindow(FALSE);
	
	this->ShowWindow(SW_SHOWNORMAL);
	HRESULT hr;
	try
	{
		this->m_nInfo = "ÕýÔÚ½øÈëϵͳ,ÇëÉÔºò...";
			this->UpdateData(FALSE);
	
		Sleep(2000);
		hr = m_pConnection.CreateInstance(__uuidof(Connection));
		if (SUCCEEDED(hr))
		{
			m_pConnection->ConnectionString = "File Name=Data.udl";
			m_pConnection->ConnectionTimeout = 10;
			hr = m_pConnection->Open("","","",adConnectUnspecified);
			while (FAILED(hr))
			{
				hr = m_pConnection->Open("","","",adConnectUnspecified);
			}
			
			Sleep(1000);
			this->OnOK();

		} 
		else
		{
			MessageBox(_T("µÇ½ʧ°Ü!"),_T("´íÎó"),0+16+0);
			SendMessage(WM_CLOSE,0,0);
		}
	}
	catch (_com_error e)
	{
		
		_bstr_t bstrSource(e.Source());
		_bstr_t bstrDescription(e.Description());
		AfxMessageBox(bstrSource+bstrDescription);
		exit(1);
		
	}
	
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
Exemplo n.º 16
0
void CADORecordset::dump_com_error(_com_error &e)
{
    TCHAR ErrorStr[1024];
    _bstr_t bstrSource(e.Source());
    _bstr_t bstrDescription(e.Description());
    swprintf(ErrorStr,sizeof(ErrorStr)/sizeof(ErrorStr[0]),
        _T("CADORecordset Error\r\nCode = %08lx\r\nCode meaning = %s\r\nSource = %s\r\nDescription = %s\r\n"),
        e.Error(),
        e.ErrorMessage(),
        (LPCTSTR)bstrSource,
        (LPCTSTR)bstrDescription );
    m_strLastError  = _T("Query = ") + GetQuery() + _T('\r\n') + ErrorStr;
    m_dwLastError   = e.Error();
}
Exemplo n.º 17
0
void CADOParameter::dump_com_error(_com_error &e)
{
	CString ErrorStr;
	
	_bstr_t bstrSource(e.Source());
	_bstr_t bstrDescription(e.Description());
	ErrorStr.Format( "CADOParameter Error\n\tCode = %08lx\n\tCode meaning = %s\n\tSource = %s\n\tDescription = %s\n",
		e.Error(), e.ErrorMessage(), (LPCSTR)bstrSource, (LPCSTR)bstrDescription );
	m_strLastError = ErrorStr;
	m_dwLastError = e.Error();
	#ifdef _DEBUG
		AfxMessageBox(ErrorStr, MB_OK | MB_ICONERROR);
	#endif	
	throw CADOException(e.Error(), e.Description());
}
Exemplo n.º 18
0
void CADODatabase::dump_com_error(_com_error &e)
{
	TCHAR ErrorStr[1024];
    _bstr_t bstrSource(e.Source());
    _bstr_t bstrDescription(e.Description());
	swprintf(ErrorStr,sizeof(ErrorStr)/sizeof(ErrorStr[0]),
        _T("CADODatabase Error\r\nCode = %08lx\r\nCode meaning = %s\r\nSource = %s\r\nDescription = %s\r\n"),
		e.Error(), 
        e.ErrorMessage(), 
        (LPCTSTR)bstrSource,
        (LPCTSTR)bstrDescription);
    m_strErrorDescription   = (LPCTSTR)bstrDescription ;
    m_strLastError          = wstring(_T("Connection String = "))/* + GetConnectionString() **/+ _T('\r\n') + ErrorStr;
    m_dwLastError           = e.Error(); 
}
Exemplo n.º 19
0
void CADOParameter::dump_com_error(_com_error &e)
{
    TCHAR ErrorStr[1024];
    _bstr_t bstrSource(e.Source());
    _bstr_t bstrDescription(e.Description());
    swprintf(ErrorStr,sizeof(ErrorStr)/sizeof(ErrorStr[0]),
        _T("cmADOParameter Error\n\tCode = %08lx\n\tCode meaning = %s\n\tSource = %s\n\tDescription = %s\n"),
        e.Error(), 
        e.ErrorMessage(), 
        (LPCTSTR)bstrSource,
        (LPCTSTR)bstrDescription );
    m_strLastError = ErrorStr;
    m_dwLastError = e.Error();
    throw CADOException(e.Error(), e.Description());
}
Exemplo n.º 20
0
void dump_com_error(_com_error &e)
{
	_bstr_t bstrSource(e.Source());
	_bstr_t bstrDescription(e.Description());
	TCHAR szTemp[1024];
	CString csMsg = "Oops - hit an error!\n";
	wsprintf(szTemp, _T("Code = %08lx\n"), e.Error());
	csMsg += szTemp;
	wsprintf(szTemp, _T("Code meaning = %s\n"), e.ErrorMessage());
	csMsg += szTemp;
	wsprintf(szTemp, _T("Source = %s\n"), bstrSource.length() ? (LPCTSTR)bstrSource : _T("null"));
	csMsg += szTemp;
	wsprintf(szTemp, _T("Description = %s\n"), bstrDescription.length() ? (LPCTSTR)bstrDescription : _T("null"));
	csMsg += szTemp;
	AfxMessageBox(csMsg);
}
Exemplo n.º 21
0
void CADORecordset::dump_com_error(_com_error &e)
{
	CString ErrorStr;
	
	_bstr_t bstrSource(e.Source());
	_bstr_t bstrDescription(e.Description());
	ErrorStr.Format( "CADORecordset Error\n\tCode = %08lx\n\tCode meaning = %s\n\tSource = %s\n\tDescription = %s\n",
		e.Error(), e.ErrorMessage(), (LPCSTR)bstrSource, (LPCSTR)bstrDescription );
	ErrorStr.Format( "Error Code = %08lx\n\t %s\n",	e.Error(), (LPCSTR)bstrDescription );
	m_strLastError = _T("Query = " + GetQuery() + " " + (LPCSTR)bstrDescription);
	m_dwLastError = e.Error();
	#ifdef _DEBUG
		AfxMessageBox( ErrorStr, MB_OK | MB_ICONERROR );
	#endif	
	throw CADOException(e.Error(), m_strLastError);
}
Exemplo n.º 22
0
void CADODatabase::dump_com_error(_com_error &e)
{
	CString ErrorStr;
	
	_bstr_t bstrSource(e.Source());
	_bstr_t bstrDescription(e.Description());
	ErrorStr.Format( "CADODataBase Error\n\tCode = %08lx\n\tCode meaning = %s\n\tSource = %s\n\tDescription = %s\n",
		e.Error(), e.ErrorMessage(), (LPCSTR)bstrSource, (LPCSTR)bstrDescription);
	m_strErrorDescription = (LPCSTR)bstrDescription ;
	m_strLastError = _T("Connection String = " + GetConnectionString() + '\n' + ErrorStr);
	m_dwLastError = e.Error(); 
	#ifdef _DEBUG
		AfxMessageBox(ErrorStr, MB_OK | MB_ICONERROR );
	#endif
	throw CADOException(e.Error(), e.Description());
}
Exemplo n.º 23
0
void CAdo::COMERRORMSG(_com_error &e)
{

	CString sMsg, errMsg;
    /////////////////////////////////////////////////////////////////////////
    // Com errors.
    _bstr_t bstrSource(e.Source());
    _bstr_t bstrDescription(e.Description());
    errMsg.Format("%08lx : %s\n", e.Error(), e.ErrorMessage());
    sMsg += errMsg;
    errMsg.Format("Source = %s\n", (LPCSTR) bstrSource);
    sMsg += errMsg;
    errMsg.Format("Description = %s", (LPCSTR) bstrDescription);
    sMsg += errMsg;
    AfxMessageBox(sMsg, MB_ICONSTOP);


}
Exemplo n.º 24
0
void CADOCommand::dump_com_error(_com_error &e)
{
	CString ErrorStr;
	
	
	_bstr_t bstrSource(e.Source());
	_bstr_t bstrDescription(e.Description());
	ErrorStr.Format( _T("CADOCommand Error\n\tCode = %08lx\n\tCode meaning = %s\n\tSource = %s\n\tDescription = %s\n"),
		e.Error(), e.ErrorMessage(), (LPCSTR)bstrSource, (LPCSTR)bstrDescription );
	m_strLastError = ErrorStr;
	m_dwLastError = e.Error();
	#ifdef _DEBUG
		AfxMessageBox(ErrorStr, MB_OK | MB_ICONERROR);
#else
	g_log.Trace(LOGL_HIG, LOGC_ERROR, __TFILE__, __LINE__, bstrDescription) ;
	#endif	
	throw CADOException(e.Error(), e.Description());
}
Exemplo n.º 25
0
static void
fillExcepInfo (EXCEPINFO *pExcepInfo,
               HRESULT hresult,
               const char *source,
               const char *description)
{
    if (pExcepInfo != 0) {
        memset(pExcepInfo, 0, sizeof(EXCEPINFO));
        pExcepInfo->scode = hresult;

        _bstr_t bstrSource(source);
        pExcepInfo->bstrSource = SysAllocString(bstrSource);

        if (description != 0) {
            _bstr_t bstrDescription(description);
            pExcepInfo->bstrDescription = SysAllocString(bstrDescription);
        }
    }
}
Exemplo n.º 26
0
void CWebSite::OnRescan(GUID* iid)
{
	ATLASSERT(0);
	try
	{
		WCHAR sql[256];
		swprintf(sql, L"INSERT INTO files (filename) VALUES ('%s')", L"test.htm");

		_variant_t	va;
		m_siteDataConnection->Execute(sql, &va, ADODB::adCmdText);

		m_siteDataConnection->Close();
	}
	catch (_com_error &e)
   {
      _bstr_t bstrSource(e.Source());
      _bstr_t bstrDescription(e.Description());
      
		CUString msg;
      msg.Format("\n\tSource :  %s \n\tdescription : %s \n ",(LPCSTR)bstrSource,(LPCSTR)bstrDescription);

		MessageBox(NULL, msg, "", MB_OK);
   }
}
Exemplo n.º 27
0
bool CPokerTrackerThread::QueryName(const char * query_name, const char * scraped_name, char * best_name)
{
	int				lev_dist = 0, bestLD = 0, bestLDindex = 0;
	PGresult		*res = NULL;
	bool			result = false;
	CLevDistance	myLD;
	int				siteid = 0;
	double			Levenshtein_distance_matching_factor = 0.2;

	//No more unnecessary queries when we don't even have a siteid to check
	siteid = pt_lookup.GetSiteId();
	if (siteid == k_undefined)  return false;

	if (!_connected || PQstatus(_pgconn) != CONNECTION_OK)
		return false;

	if (0 == strlen(query_name))
		return false;

	CString query;
	query.Format("SELECT player_name FROM player WHERE player_name like '%s' AND id_site=%i",
		query_name, siteid);
	try
	{
		res = PQexec(_pgconn, query);
	}
	catch (_com_error &e)
	{
		write_log(preferences.debug_pokertracker(), "[PokerTracker] Postgres Query error:\n");
		write_log(preferences.debug_pokertracker(), "[PokerTracker] \tCode = %08lx\n", e.Error());
		write_log(preferences.debug_pokertracker(), "[PokerTracker] \tCode meaning = %s\n", e.ErrorMessage());
		_bstr_t bstrSource(e.Source());
		_bstr_t bstrDescription(e.Description());
		write_log(preferences.debug_pokertracker(), "[PokerTracker] \tSource = %s\n", (LPCTSTR) bstrSource);
		write_log(preferences.debug_pokertracker(), "[PokerTracker] \tDescription = %s\n", (LPCTSTR) bstrDescription);
		write_log(preferences.debug_pokertracker(), "[PokerTracker] \tQuery = [%s]\n", query);
	}

	// We got nothing, return false
	if (PQntuples(res) == 0)
	{
		result = false;
	}

	// If we get one tuple, all is good - return the one name
	if (PQntuples(res) == 1)
	{
		lev_dist = myLD.LD(scraped_name, PQgetvalue(res, 0, 0));

		if (lev_dist<=(int)strlen(PQgetvalue(res, 0, 0))*Levenshtein_distance_matching_factor )
		{
	     	strcpy_s(best_name, k_max_length_of_playername, PQgetvalue(res, 0, 0));
			result = true;
		}
		else {
			result = false;
		}
	}

	// We got more than one tuple, figure the Levenshtein distance for all of them
	// and return the best
	else if ((PQntuples(res) > 1))
	{
		bestLD = 999;
		for (int i=0; i<PQntuples(res); i++)
		{
			lev_dist = myLD.LD(scraped_name, PQgetvalue(res, i, 0));

			if (lev_dist<bestLD && lev_dist<(int)strlen(PQgetvalue(res, i, 0))*Levenshtein_distance_matching_factor ) 
			{
				bestLD = lev_dist;
				bestLDindex = i;
			}
		}
		if (bestLD != 999)
		{
			strcpy_s(best_name, k_max_length_of_playername, PQgetvalue(res, bestLDindex, 0));
			result = true;
		}
		else
		{
			result = false;
		}
	}

	PQclear(res);
	return result;
}
Exemplo n.º 28
0
double CPokerTrackerThread::UpdateStat(int m_chr, int stat)
{
	PGresult	*res = NULL;
	double		result = k_undefined;
	clock_t		updStart, updEnd;
	int			duration;

	int sym_elapsed = p_symbol_engine_time->elapsed();

	//No more unnecessary queries when we don't even have a siteid to check
	int siteid = pt_lookup.GetSiteId();
	if (siteid == k_undefined)
		return k_undefined;

	if (!_connected || PQstatus(_pgconn) != CONNECTION_OK)
		return k_undefined;

	assert(m_chr >= k_first_chair);
	assert(m_chr <= k_last_chair);
	assert(stat >= 0);
	assert(stat < PT_DLL_GetNumberOfStats());

	// get query string for the requested statistic
	CString query = PT_DLL_GetQuery(stat,
		p_symbol_engine_isomaha->isomaha(),
		p_symbol_engine_istournament->istournament(),
		siteid, _player_data[m_chr].pt_name);

	// Do the query against the PT database
	updStart = clock();
	try
	{
		// See if we can find the player name in the database
		write_log(preferences.debug_pokertracker(), 
			"[PokerTracker] Querying %s for m_chr %d: %s\n", 
			PT_DLL_GetBasicSymbolNameWithoutPTPrefix(stat), 
			m_chr, query);
		res = PQexec(_pgconn, query);
	}
	catch (_com_error &e)
	{
		write_log(preferences.debug_pokertracker(), "[PokerTracker] ERROR\n");
		write_log(preferences.debug_pokertracker(), _T("\tCode = %08lx\n"), e.Error());
		write_log(preferences.debug_pokertracker(), _T("\tCode meaning = %s\n"), e.ErrorMessage());
		_bstr_t bstrSource(e.Source());
		_bstr_t bstrDescription(e.Description());
		write_log(preferences.debug_pokertracker(), _T("\tSource = %s\n"), (LPCTSTR) bstrSource);
		write_log(preferences.debug_pokertracker(), _T("\tDescription = %s\n"), (LPCTSTR) bstrDescription);
		write_log(preferences.debug_pokertracker(), _T("\tQuery = [%s]\n"), query);
	}
	
	updEnd = clock();
	duration = (int) ((double)(updEnd - updStart) / 1000);
	if (duration >= 3)
		write_log(preferences.debug_pokertracker(), "[PokerTracker] Query time in seconds: [%d]\n", duration);

	// Check query return code
	if (PQresultStatus(res) != PGRES_TUPLES_OK)
	{
		switch (PQresultStatus(res))
		{
		case PGRES_COMMAND_OK:
			write_log(preferences.debug_pokertracker(), "[PokerTracker] PGRES_COMMAND_OK: %s [%s]\n", PQerrorMessage(_pgconn), query);
			break;
		case PGRES_EMPTY_QUERY:
			write_log(preferences.debug_pokertracker(), "[PokerTracker] PGRES_EMPTY_QUERY: %s [%s]\n", PQerrorMessage(_pgconn), query);
			break;
		case PGRES_BAD_RESPONSE:
			write_log(preferences.debug_pokertracker(), "[PokerTracker] PGRES_BAD_RESPONSE: %s [%s]\n", PQerrorMessage(_pgconn), query);
			break;
		case PGRES_COPY_OUT:
			write_log(preferences.debug_pokertracker(), "[PokerTracker] PGRES_COPY_OUT: %s [%s]\n", PQerrorMessage(_pgconn), query);
			break;
		case PGRES_COPY_IN:
			write_log(preferences.debug_pokertracker(), "[PokerTracker] PGRES_COPY_IN: %s [%s]\n", PQerrorMessage(_pgconn), query);
			break;
		case PGRES_NONFATAL_ERROR:
			write_log(preferences.debug_pokertracker(), "[PokerTracker] PGRES_NONFATAL_ERROR: %s [%s]\n", PQerrorMessage(_pgconn), query);
			break;
		case PGRES_FATAL_ERROR:
			write_log(preferences.debug_pokertracker(), "[PokerTracker] PGRES_FATAL_ERROR: %s [%s]\n", PQerrorMessage(_pgconn), query);
			break;
		default:
			write_log(preferences.debug_pokertracker(), "[PokerTracker] GENERIC ERROR: %s [%s]\n", PQerrorMessage(_pgconn), query);
			break;
		}
	}
	else
	{
		if (PQgetisnull(res,0,0) != 1)
		{
			result = atof(PQgetvalue(res,0,0));
			write_log(preferences.debug_pokertracker(), 
				"[PokerTracker] Query %s for m_chr %d success: %f\n", 
				PT_DLL_GetBasicSymbolNameWithoutPTPrefix(stat), 
				m_chr, result);
		}
		PQclear(res);

		// update cache with new values
		PT_DLL_SetStat(stat, m_chr, result);
	}

	return result;
}
STDMETHODIMP InterfaceDatabase::CreateInternalDatabase()
{
   try
   {
      if (!config_)
         return GetAccessDenied();

   	if (!GetIsServerAdmin())
         return GetAccessDenied();
   
      // Make sure we have the latest settings.
      ini_file_settings_->LoadSettings();
   
      HM::String sDirectory = ini_file_settings_->GetDatabaseDirectory();
      HM::String sDatabaseName = "hMailServer";
      HM::String sPassword = HM::PasswordGenerator::Generate();
   
      HM::String sErrorMessage;
      if (!HM::SQLCEConnection::CreateDatabase(sDirectory, sDatabaseName, sPassword, sErrorMessage))
         return COMError::GenerateError(sErrorMessage);
   
      HM::String sEmpty;
   
      // Create a settings object which we use to connect to the server.
      std::shared_ptr<HM::DatabaseSettings> pSettings = std::shared_ptr<HM::DatabaseSettings>(
         new HM::DatabaseSettings(sEmpty, sDatabaseName, sEmpty, sPassword, sDirectory, sEmpty, HM::DatabaseSettings::TypeMSSQLCompactEdition, 0));
   
      // Connect to the new database
      std::shared_ptr<HM::DALConnection> pConn = HM::DALConnectionFactory::CreateConnection(pSettings);
   
      if (pConn->Connect(sErrorMessage) != HM::DALConnection::Connected)
      {
         return COMError::GenerateError(sErrorMessage);
      }
   
      // Create the tables
      HM::SQLScriptRunner scriptRunner;
      if (!scriptRunner.ExecuteScript(pConn, pSettings->GetDefaultScript(), sErrorMessage))
      {
         return COMError::GenerateError(sErrorMessage);
      }
   
      ini_file_settings_->SetDatabaseDirectory(sDirectory);
      ini_file_settings_->SetDatabaseType(HM::DatabaseSettings::TypeMSSQLCompactEdition);
      ini_file_settings_->SetUsername("");
      ini_file_settings_->SetPassword(sPassword);
      ini_file_settings_->SetDatabasePort(0);
      ini_file_settings_->SetDatabaseServer("");
      ini_file_settings_->SetDatabaseName(sDatabaseName);
      ini_file_settings_->SetIsInternalDatabase(true);
   
      return S_OK;   
   }
   catch (_com_error &err)
   {
      _bstr_t bstrSource(err.Source());
      _bstr_t bstrDescription(err.Description());

      LPCSTR lpcSource = bstrSource;
      HM::String sErrSource = lpcSource;

      LPCSTR lpcDesc = bstrDescription;
      HM::String sErrDesc = lpcDesc;

      return COMError::GenerateGenericMessage();
   }
   catch (...)
   {
      return COMError::GenerateGenericMessage();
   }
}
Exemplo n.º 30
0
bool CPokerTrackerThread::QueryName(const char * query_name, const char * scraped_name, char * best_name)
{
	char			strQry[k_max_length_of_query] = {0};
	int				lev_dist = 0, bestLD = 0, bestLDindex = 0;
	PGresult		*res = NULL;
	char			siteidstr[k_max_length_of_site_id] = {0};
	bool			result = false;
	CLevDistance	myLD;
	int				siteid = 0;
	static int		_last_siteid = -1;
	double			Levenshtein_distance_matching_factor = 0.2;

	//No more unnecessary queries when we don't even have a siteid to check
	siteid = pt_lookup.GetSiteId();
	if (siteid == k_undefined)  return false;

	// siteid has changed -- we're using ManualMode
	if (siteid != _last_siteid)
	{
		ClearAllStats();
		_last_siteid = siteid;
	}

	if (!_connected || PQstatus(_pgconn) != CONNECTION_OK)
		return false;

	if (0 == strlen(query_name))
		return false;

	sprintf_s(siteidstr, k_max_length_of_site_id, "%d", siteid);

	// PT version 3 name query
	strcpy_s(strQry, k_max_length_of_query, "SELECT player_name FROM player WHERE player_name like '");
	strcat_s(strQry, k_max_length_of_query, query_name);
	strcat_s(strQry, k_max_length_of_query, "' AND id_site=");
	strcat_s(strQry, k_max_length_of_query, siteidstr);
	
	try
	{
		res = PQexec(_pgconn, strQry);
	}
	catch (_com_error &e)
	{
		write_log_pokertracker(prefs.debug_pokertracker(), "Postgres Query error:\n");
		write_log_pokertracker(prefs.debug_pokertracker(), "\tCode = %08lx\n", e.Error());
		write_log_pokertracker(prefs.debug_pokertracker(), "\tCode meaning = %s\n", e.ErrorMessage());
		_bstr_t bstrSource(e.Source());
		_bstr_t bstrDescription(e.Description());
		write_log_pokertracker(prefs.debug_pokertracker(), "\tSource = %s\n", (LPCTSTR) bstrSource);
		write_log_pokertracker(prefs.debug_pokertracker(), "\tDescription = %s\n", (LPCTSTR) bstrDescription);
		write_log_pokertracker(prefs.debug_pokertracker(), "\tQuery = [%s]\n", strQry);
	}

	// We got nothing, return false
	if (PQntuples(res) == 0)
	{
		result = false;
	}

	// If we get one tuple, all is good - return the one name
	if (PQntuples(res) == 1)
	{
		lev_dist = myLD.LD(scraped_name, PQgetvalue(res, 0, 0));

		if (lev_dist<=(int)strlen(PQgetvalue(res, 0, 0))*Levenshtein_distance_matching_factor )
		{
	     	strcpy_s(best_name, k_max_length_of_playername, PQgetvalue(res, 0, 0));
			result = true;
		}
		else {
			result = false;
		}
	}

	// We got more than one tuple, figure the Levenshtein distance for all of them
	// and return the best
	else if ((PQntuples(res) > 1))
	{
		bestLD = 999;
		for (int i=0; i<PQntuples(res); i++)
		{
			lev_dist = myLD.LD(scraped_name, PQgetvalue(res, i, 0));

			if (lev_dist<bestLD && lev_dist<(int)strlen(PQgetvalue(res, i, 0))*Levenshtein_distance_matching_factor ) 
			{
				bestLD = lev_dist;
				bestLDindex = i;
			}
		}
		if (bestLD != 999)
		{
			strcpy_s(best_name, k_max_length_of_playername, PQgetvalue(res, bestLDindex, 0));
			result = true;
		}
		else
		{
			result = false;
		}
	}

	PQclear(res);
	return result;
}