summaryrefslogtreecommitdiff
path: root/protocols/CurrencyRates/src/DBUtils.cpp
blob: 05e0e79c056eb1104b8188c7b0f189b16895962b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "StdAfx.h"

CMStringW GetNodeText(const TiXmlElement *pNode)
{
	auto *pszText = pNode->GetText();
	if (pszText)
		return Utf2T(pszText).get();

	return CMStringW();
}

bool CurrencyRates_DBWriteDouble(MCONTACT hContact, const char *szModule, const char *szSetting, double dValue)
{
	return 0 == db_set_blob(hContact, szModule, szSetting, &dValue, sizeof(dValue));
}

bool CurrencyRates_DBReadDouble(MCONTACT hContact, const char *szModule, const char *szSetting, double& rdValue)
{
	DBVARIANT dbv = {};
	dbv.type = DBVT_BLOB;

	bool bResult = ((0 == db_get(hContact, szModule, szSetting, &dbv)) && (DBVT_BLOB == dbv.type));
	if (bResult)
		rdValue = *reinterpret_cast<double*>(dbv.pbVal);

	db_free(&dbv);
	return bResult;
}

void FixInvalidChars(CMStringW &s)
{
	s.Replace('\\', '_');
	s.Replace('/', '_');
	s.Replace(':', '_');
	s.Replace('*', '_');
	s.Replace('\"', '_');
	s.Replace('<', '_');
	s.Replace('>', '_');
	s.Replace('/', '_');
}