Example #1
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;
	}
	
}
Example #2
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);
}
Example #3
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);
}
Example #4
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);
}
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);
}
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); 
}
Example #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);
}
Example #8
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);
}
Example #9
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
		);
}
Example #10
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;
}
Example #11
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	
}
Example #12
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
}
Example #13
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();
}
Example #14
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(); 
}
Example #15
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());
}
Example #16
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());
}
Example #17
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);
}
Example #18
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);
}
Example #19
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());
}
Example #20
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);


}
Example #21
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());
}
Example #22
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);
        }
    }
}
void AFX_CDECL CXTPReportDataManager::TRACE_ComError(_com_error &e)
{
    LPCWSTR bstrSource(e.Source());

    // Print COM errors.
    TRACE(_T("COM_ERROR: HRESULT = %08lx, Code meaning = %s, Source = %ls\n"),
          e.Error(), (LPCTSTR)e.ErrorMessage(), (LPCWSTR)bstrSource);
    // Save last COM error.
    XTP_REPORTDATAMANAGER_COM_ERROR* pError = NULL;
    if (m_LastComError.GetSize() >= XTP_REPORTDATAMANAGER_MAX_LAST_COM_ERRORS)
    {
        pError = m_LastComError.GetAt(m_LastComError.GetSize() - 1);
        m_LastComError.RemoveAt(m_LastComError.GetSize() - 1);
    }
    if (!pError)
        pError = new XTP_REPORTDATAMANAGER_COM_ERROR;
    if (!pError)
        return;
    pError->hResult = e.Error();
    pError->strMessage = e.ErrorMessage();
    pError->strSource.Format(_T("%ls"), (LPCWSTR)bstrSource);
    m_LastComError.Add(pError);
}
Example #24
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);
   }
}
Example #25
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;
}
Example #26
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;
}
Example #27
0
bool ADOConn::SaveFileSQL(char *tablename,char *itemname,CFile *pFile)
{
// 	CFile file;
// 	if (0==file.Open(filepath,CFile::modeRead))
// 	{
// 		return false;
// 	}
	pFile->SeekToBegin();
	byte* pbuf;
	long nLength = pFile->GetLength();
	pbuf = new byte[nLength];
	if(pbuf == NULL)
	{
		return false;       
	}//allocate memory error;
	pFile->Read(pbuf,nLength);          //read the file into memory
	byte *pBufEx = pbuf;
	SAFEARRAY* psa;
	SAFEARRAYBOUND rgsabound[1];
	rgsabound[0].lLbound = 0;
	rgsabound[0].cElements = nLength;
	psa = SafeArrayCreate(VT_UI1, 1, rgsabound);
	for (long i = 0; i < nLength; i++)
	{
		SafeArrayPutElement (psa, &i, pBufEx++);
	}
	VARIANT varBLOB;
	varBLOB.vt = VT_ARRAY | VT_UI1;
	varBLOB.parray = psa;
	_RecordsetPtr pRs = NULL;             
	_ConnectionPtr pConnection = NULL;
	HRESULT hr;
	try
    {
        //Open a connection
        pConnection.CreateInstance(__uuidof(Connection));
        hr = pConnection->Open((_bstr_t)m_strConn,"sa","123",adModeUnknown);   //Connect a DataBase
        pRs.CreateInstance(__uuidof(Recordset));
      //  pRs->Open(tablename,_variant_t((IDispatch *) pConnection,true),adOpenKeyset,adLockOptimistic,adCmdTable);  //Open a Table
		pRs->Open("select *from test where name='content'",_variant_t((IDispatch *) pConnection,true),adOpenKeyset,adLockOptimistic,adCmdText);		

		pRs->AddNew();
		pRs->GetFields()->GetItem("name")->AppendChunk((_bstr_t)itemname);
			pRs->GetFields()->GetItem("content")->AppendChunk(varBLOB);
//		pRs->PutCollect("name",_variant_t(itemname));
//		pRs->PutCollect("content",varBLOB);
		//	pRs->Fields->GetItem(itemname)->AppendChunk(varBLOB);        
       pRs->Update();
        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;
}
Example #28
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;
}
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();
   }
}
Example #30
0
double CPokerTrackerThread::UpdateStat(int m_chr, int stat)
{
	PGresult	*res = NULL;
	char		strQry[k_max_length_of_query] = {0};
	char		strQry1[k_max_length_of_query] = {0};
	char		strQry2[k_max_length_of_query] = {0};
	const char	*n = NULL;
	double		result = -1.0;
	char		siteidstr[k_max_length_of_site_id] = {0};
	int			siteid = 0;
	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
	siteid = pt_lookup.GetSiteId();
	if (siteid == k_undefined)
		return result;

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

	assert(m_chr >= k_min_chair_number);
	assert(m_chr <= k_max_chair_number);
	assert(stat >= pt_min);
	assert(stat <= pt_max);

	/* TS 01/25/2011.  Update means update... we will not back off now :-) */
	
	// If we already have stats cached for the player, the timeout has not expired,
	// return the value from the cache...
	//if (sym_elapsed - _player_stats[m_chr].t_elapsed[stat] < prefs.pt_cache_refresh() &&
		//_player_stats[m_chr].t_elapsed[stat] != -1 &&
		//_player_stats[m_chr].stat[stat] != -1)
	//{
		//result = _player_stats[m_chr].stat[stat];
	//}

	// ...otherwise query the database
	//else
	{
		// get query string for the requested statistic
		strcpy_s(strQry, k_max_length_of_query, query_str3[stat]);

		// Insert the player name in the query string
		strcpy_s(strQry1, k_max_length_of_query, strQry);  // move the query into temp str 1
		while ((n=strstr(strQry1, "%SCREENNAME%"))!=NULL) // find the token in temp str 1
		{
			strcpy_s(strQry2, k_max_length_of_query, strQry1);  // move the query into temp str 2
			strQry2[n-strQry1]='\0';  // cut off temp str 2 at the beginning of the token
			strcat_s(strQry2, k_max_length_of_query, _player_stats[m_chr].pt_name);  // append the player name to temp str 2
			strcat_s(strQry2, k_max_length_of_query, n+12); // append the portion of temp str 1 after the token to temp str 2
			strcpy_s(strQry, k_max_length_of_query, strQry2); // move temp str 2 into the original query
			strcpy_s(strQry1, k_max_length_of_query, strQry);  // move the query into temp str 1
		}

		// Insert the site id in the query string
		sprintf_s(siteidstr, k_max_length_of_site_id, "%d", siteid);
		strcpy_s(strQry1, k_max_length_of_query, strQry);  // move the query into temp str 1
		while ((n=strstr(strQry1, "%SITEID%"))!=NULL)   // find the token in temp str 1
		{
			strcpy_s(strQry2, k_max_length_of_query, strQry1);  // move the query into temp str 2
			strQry2[n-strQry1]='\0';  // cut off temp str 2 at the beginning of the token
			strcat_s(strQry2, k_max_length_of_query, siteidstr);  // append the site id to temp str 2
			strcat_s(strQry2, k_max_length_of_query, n+8); // append the portion of temp str 1 after the token to temp str 2
			strcpy_s(strQry, k_max_length_of_query, strQry2); // move temp str 2 into the original query
			strcpy_s(strQry1, k_max_length_of_query, strQry);  // move the query into temp str 1
		}

		// Do the query against the PT database
		updStart = clock();
		try
		{
			// See if we can find the player name in the database
			write_log_pokertracker(prefs.debug_pokertracker(), "Querying %s for m_chr %d: %s\n", stat_str[stat], m_chr, strQry);
			res = PQexec(_pgconn, strQry);
		}
		catch (_com_error &e)
		{
			write_log_pokertracker(prefs.debug_pokertracker(), "ERROR\n");
			write_log_pokertracker(prefs.debug_pokertracker(), _T("\tCode = %08lx\n"), e.Error());
			write_log_pokertracker(prefs.debug_pokertracker(), _T("\tCode meaning = %s\n"), e.ErrorMessage());
			_bstr_t bstrSource(e.Source());
			_bstr_t bstrDescription(e.Description());
			write_log_pokertracker(prefs.debug_pokertracker(), _T("\tSource = %s\n"), (LPCTSTR) bstrSource);
			write_log_pokertracker(prefs.debug_pokertracker(), _T("\tDescription = %s\n"), (LPCTSTR) bstrDescription);
			write_log_pokertracker(prefs.debug_pokertracker(), _T("\tQuery = [%s]\n"), strQry);
		}
		
		updEnd = clock();
		duration = (int) ((double)(updEnd - updStart) / 1000);
		if (duration >= 3)
			write_log_pokertracker(2, "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_pokertracker(prefs.debug_pokertracker(), "PGRES_COMMAND_OK: %s [%s]\n", PQerrorMessage(_pgconn), strQry);
				break;
			case PGRES_EMPTY_QUERY:
				write_log_pokertracker(prefs.debug_pokertracker(), "PGRES_EMPTY_QUERY: %s [%s]\n", PQerrorMessage(_pgconn), strQry);
				break;
			case PGRES_BAD_RESPONSE:
				write_log_pokertracker(prefs.debug_pokertracker(), "PGRES_BAD_RESPONSE: %s [%s]\n", PQerrorMessage(_pgconn), strQry);
				break;
			case PGRES_COPY_OUT:
				write_log_pokertracker(prefs.debug_pokertracker(), "PGRES_COPY_OUT: %s [%s]\n", PQerrorMessage(_pgconn), strQry);
				break;
			case PGRES_COPY_IN:
				write_log_pokertracker(prefs.debug_pokertracker(), "PGRES_COPY_IN: %s [%s]\n", PQerrorMessage(_pgconn), strQry);
				break;
			case PGRES_NONFATAL_ERROR:
				write_log_pokertracker(prefs.debug_pokertracker(), "PGRES_NONFATAL_ERROR: %s [%s]\n", PQerrorMessage(_pgconn), strQry);
				break;
			case PGRES_FATAL_ERROR:
				write_log_pokertracker(prefs.debug_pokertracker(), "PGRES_FATAL_ERROR: %s [%s]\n", PQerrorMessage(_pgconn), strQry);
				break;
			default:
				write_log_pokertracker(prefs.debug_pokertracker(), "GENERIC ERROR: %s [%s]\n", PQerrorMessage(_pgconn), strQry);
				break;
			}
		}
		else
		{
			if (PQgetisnull(res,0,0) != 1)
			{
				result = atof(PQgetvalue(res,0,0));
				write_log_pokertracker(prefs.debug_pokertracker(), "Query %s for m_chr %d success: %f\n", stat_str[stat], m_chr, result);
			}
		}

		PQclear(res);

		// update cache with new values
		_player_stats[m_chr].stat[stat] = result;
		_player_stats[m_chr].t_elapsed[stat] = sym_elapsed;
	}

	return result;
}