blob: 2f193024b09c2cc2bb664f7c95f05a72d2df7277 (
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
|
#include "connectionLoader.h"
#include "../libsqlitepp/connection.h"
#include "sql-modSQLite.h"
#include <buffer.h>
#include <scripts.h>
#include <logger.h>
#include <boost/filesystem/operations.hpp>
#include "mockDatasource.h"
typedef SQLite::Connection SQLiteConnection;
DECLARE_GENERIC_LOADER("sqlite", ConnectionLoader, SQLiteConnection)
MockSQLiteDatabase::MockSQLiteDatabase(const std::string & name, const std::vector<boost::filesystem::path> & ss) :
MockDatabase(name),
testDbPath(boost::filesystem::path("/tmp") / "sqliteut" / stringbf("%d", getpid()) / stringbf("%d", ++MockConnectionLoader::mocked))
{
CreateNewDatabase();
PlaySchemaScripts(ss);
}
DB::Connection *
MockSQLiteDatabase::openConnection() const
{
return InstanceMap<ConnectionLoader, std::string>::Get<std::invalid_argument>("sqlite")->create(testDbPath.string());
}
MockSQLiteDatabase::~MockSQLiteDatabase()
{
DropDatabase();
}
void MockSQLiteDatabase::DropDatabase() const
{
Logger()->messagebf(LOG_INFO, "Deleting database %s", testDbPath);
boost::filesystem::remove(testDbPath);
}
void MockSQLiteDatabase::CreateNewDatabase() const
{
Logger()->messagebf(LOG_INFO, "Creating new database at %s", testDbPath);
boost::filesystem::create_directories(testDbPath.parent_path());
delete openConnection();
}
|