summaryrefslogtreecommitdiff
path: root/project2/sql/sql-modODBC.cpp
blob: 29d24412896a05d0d939f96e9857edc872160ada (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
#include "connectionLoader.h"
#include "../libodbcpp/connection.h"
#include "sql-modODBC.h"
#include <misc.h>
#include <scripts.h>
#include <logger.h>

typedef ODBC::Connection ODBCConnection;
DECLARE_GENERIC_LOADER("odbc", ConnectionLoader, ODBCConnection)

MockODBCDatabase::MockODBCDatabase(const std::string & masterdb, const std::string & name, const std::vector<boost::filesystem::path> & ss) :
	MockServerDatabase(masterdb, name, "odbc")
{
	CreateNewDatabase();
	PlaySchemaScripts(ss);
}

DB::Connection *
MockODBCDatabase::openConnection() const
{
	return InstanceMap<ConnectionLoader, std::string>::Get<std::invalid_argument>("odbc")->create(
			stringbf("Driver=postgresql;Database=%s;uid=postgres;servername=/run/postgresql", testDbName));
}

MockODBCDatabase::~MockODBCDatabase()
{
	DropDatabase();
}

void MockODBCDatabase::DropDatabase() const
{
	Logger()->messagebf(LOG_INFO, "Killing any active connections to database %s", testDbName);
	master->execute("SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '" + testDbName + "'");
	MockServerDatabase::DropDatabase();
}