summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--project2/sql/sql-modODBC.cpp36
-rw-r--r--project2/sql/sql-modODBC.h21
-rw-r--r--project2/sql/unittests/odbcschema.sql8
-rw-r--r--project2/sql/unittests/testodbc.cpp116
4 files changed, 0 insertions, 181 deletions
diff --git a/project2/sql/sql-modODBC.cpp b/project2/sql/sql-modODBC.cpp
deleted file mode 100644
index 5b9c858..0000000
--- a/project2/sql/sql-modODBC.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-#include "connectionLoader.h"
-#include "../libodbcpp/connection.h"
-#include "sql-modODBC.h"
-#include <buffer.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();
-}
-
diff --git a/project2/sql/sql-modODBC.h b/project2/sql/sql-modODBC.h
deleted file mode 100644
index e7d7bdb..0000000
--- a/project2/sql/sql-modODBC.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#ifndef MOCKODBCDATASOURCE_H
-#define MOCKODBCDATASOURCE_H
-
-#include "mockDatabase.h"
-#include <boost/filesystem/path.hpp>
-
-class MockODBCDatabase : public MockServerDatabase {
- public:
- MockODBCDatabase(const std::string & master, const std::string & name, const std::vector<boost::filesystem::path> & ss);
- ~MockODBCDatabase();
-
- protected:
- void DropDatabase() const override;
-
- private:
- DB::Connection * openConnection() const override;
-};
-
-#endif
-
-
diff --git a/project2/sql/unittests/odbcschema.sql b/project2/sql/unittests/odbcschema.sql
deleted file mode 100644
index 96848eb..0000000
--- a/project2/sql/unittests/odbcschema.sql
+++ /dev/null
@@ -1,8 +0,0 @@
-CREATE TABLE test(
- id int,
- fl numeric(5,2),
- string text,
- boolean bool,
- dt timestamp without time zone,
- ts interval);
-INSERT INTO test VALUES(4, 123.45, 'some text', true, '2015-04-27 23:06:03', '1 day 14:13:12');
diff --git a/project2/sql/unittests/testodbc.cpp b/project2/sql/unittests/testodbc.cpp
deleted file mode 100644
index 60db6ce..0000000
--- a/project2/sql/unittests/testodbc.cpp
+++ /dev/null
@@ -1,116 +0,0 @@
-#define BOOST_TEST_MODULE TestODBC
-#include <boost/test/unit_test.hpp>
-
-#include <mockDatasource.h>
-#include <definedDirs.h>
-#include <modifycommand.h>
-#include <selectcommand.h>
-#include <column.h>
-#include <sql-modODBC.h>
-#include "testCore.h"
-#include <sqlHandleAsVariableType.h>
-#include <definedDirs.h>
-
-class StandardMockDatabase : public MockODBCDatabase {
- public:
- StandardMockDatabase() : MockODBCDatabase("Driver=postgresql;Database=postgres;uid=postgres;servername=/run/postgresql", "odbcmock", {
- RootDir / "odbcschema.sql" })
- {
- }
-};
-
-BOOST_GLOBAL_FIXTURE( StandardMockDatabase );
-
-BOOST_FIXTURE_TEST_SUITE( Core, TestCore );
-
-BOOST_AUTO_TEST_CASE( transactions )
-{
- RdbmsDataSource * ds = CommonObjects::dataSource<RdbmsDataSource>("odbcmock");
- auto ro = ds->getReadonly();
-
- BOOST_REQUIRE_EQUAL(false, ro->inTx());
- ro->beginTx();
- BOOST_REQUIRE_EQUAL(true, ro->inTx());
- ro->rollbackTx();
- BOOST_REQUIRE_EQUAL(false, ro->inTx());
-
- ro->beginTx();
- BOOST_REQUIRE_EQUAL(true, ro->inTx());
- ro->commitTx();
- BOOST_REQUIRE_EQUAL(false, ro->inTx());
-
- ds->close();
-}
-
-BOOST_AUTO_TEST_CASE( bindAndSend )
-{
- RdbmsDataSource * ds = CommonObjects::dataSource<RdbmsDataSource>("odbcmock");
- auto rw = ds->getWritable();
-
- auto mod = rw->newModifyCommand("INSERT INTO test VALUES(?, ?, ?, ?, ?)");
- mod->bindParamI(0, testInt);
- mod->bindParamF(1, testDouble);
- mod->bindParamS(2, testString);
- mod->bindParamB(3, testBool);
- mod->bindParamT(4, testDateTime);
- mod->execute();
- delete mod;
- ds->commit();
- ds->close();
-}
-
-template<typename T>
-void
-assertColumnValueHelper(DB::SelectCommand & sel, unsigned int col, const T & t)
-{
- HandleAsVariableType h;
- sel[col].apply(h);
- BOOST_REQUIRE_EQUAL(t, h.variable.as<T>());
-}
-
-BOOST_AUTO_TEST_CASE( bindAndSelect )
-{
- RdbmsDataSource * ds = CommonObjects::dataSource<RdbmsDataSource>("odbcmock");
- auto ro = ds->getReadonly();
-
- auto select = ro->newSelectCommand("SELECT * FROM test WHERE id = ?");
- select->bindParamI(0, testInt);
- select->execute();
- int rows = 0;
- while (select->fetch()) {
- assertColumnValueHelper(*select, 0, testInt);
- assertColumnValueHelper(*select, 1, testDouble);
- assertColumnValueHelper(*select, 2, testString);
- assertColumnValueHelper(*select, 3, testBool);
- assertColumnValueHelper(*select, 4, testDateTime);
- rows += 1;
- }
- delete select;
- BOOST_REQUIRE_EQUAL(1, rows);
- ds->close();
-}
-
-BOOST_AUTO_TEST_CASE( bindAndSelectOther )
-{
- RdbmsDataSource * ds = CommonObjects::dataSource<RdbmsDataSource>("odbcmock");
- auto ro = ds->getReadonly();
-
- auto select = ro->newSelectCommand("SELECT * FROM test WHERE id != ?");
- select->bindParamI(0, testInt);
- select->execute();
- int rows = 0;
- while (select->fetch()) {
- assertColumnValueHelper(*select, 0, 4);
- assertColumnValueHelper(*select, 1, 123.45);
- assertColumnValueHelper(*select, 2, std::string("some text"));
- assertColumnValueHelper(*select, 3, true);
- assertColumnValueHelper(*select, 4, boost::posix_time::ptime_from_tm({ 3, 6, 23, 27, 3, 115, 0, 0, 0, 0, 0}));
- rows += 1;
- }
- delete select;
- BOOST_REQUIRE_EQUAL(1, rows);
- ds->close();
-}
-
-BOOST_AUTO_TEST_SUITE_END();
-