summaryrefslogtreecommitdiff
path: root/p2pvr/lib/dbClient.cpp
blob: c12cb6ccf013a2c8d6f97aae305e1b8b3fd04e20 (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
41
42
43
44
45
46
47
48
49
#include <pch.hpp>
#include "dbClient.h"
#include <sqlMergeTask.h>

void
DatabaseClient::SqlMergeColumnsInserter(SqlMergeTask * merge, const std::string & name, bool key)
{
	merge->cols.insert(new SqlMergeTask::TargetColumn(name, key));
	if (key) {
		merge->keys.insert(name);
	}
}

void
DatabaseClient::onAllDatasources(const DataSourceCall & call) const
{
	BOOST_FOREACH(const CommonObjects::DataSources::value_type & ds, CommonObjects::datasources) {
		call(ds.second);
	}
}

DatabaseClient::TxHelper::TxHelper(const DatabaseClient * dbc) :
	so(NULL,
		boost::bind(&DatabaseClient::onAllDatasources, dbc, DataSourceCall(boost::bind(&DataSource::commit, _1))),
		boost::bind(&DatabaseClient::onAllDatasources, dbc, DataSourceCall(boost::bind(&DataSource::rollback, _1))))
{
}

DatabaseClient::NoRowsFoundException::NoRowsFoundException() :
	std::runtime_error("No rows found")
{
}

VariableType
operator/(const DatabaseClient::SelectPtr & cmd, unsigned int col)
{
	HandleAsVariableType vt;
	(*cmd)[col].apply(vt);
	return vt.variable;
}

VariableType
operator/(const DatabaseClient::SelectPtr & cmd, const std::string & col)
{
	HandleAsVariableType vt;
	(*cmd)[col].apply(vt);
	return vt.variable;
}