summaryrefslogtreecommitdiff
path: root/plugins/CurrencyRates/src/DBUtils.cpp
blob: 0645387d9e5147806d22e7183166c596b8bed90a (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
#include "StdAfx.h"

std::string CurrencyRates_DBGetStringA(MCONTACT hContact, const char* szModule, const char* szSetting, const char* pszDefValue)
{
	if (pszDefValue == nullptr)
		pszDefValue = "";

	return std::string(ptrA(db_get_sa(hContact, szModule, szSetting, pszDefValue)));
}

std::wstring CurrencyRates_DBGetStringW(MCONTACT hContact, const char* szModule, const char* szSetting, const wchar_t* pszDefValue)
{
	if (pszDefValue == nullptr)
		pszDefValue = L"";

	return std::wstring(ptrW(db_get_wsa(hContact, szModule, szSetting, pszDefValue)));
}

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 = { 0 };
	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;
}