Compare commits
No commits in common. "eeae4fe6092153845ca5d1162940cccef782e660" and "9705426c3159bd5f8f2dd5ab3bfbbe157d1e3c47" have entirely different histories.
eeae4fe609
...
9705426c31
5 changed files with 23 additions and 82 deletions
55
.vscode/settings.json
vendored
55
.vscode/settings.json
vendored
|
@ -6,60 +6,5 @@
|
|||
"**/CVS": true,
|
||||
"**/.DS_Store": true,
|
||||
"**/build": true
|
||||
},
|
||||
"files.associations": {
|
||||
"cctype": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"*.ipp": "cpp",
|
||||
"array": "cpp",
|
||||
"atomic": "cpp",
|
||||
"strstream": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"bitset": "cpp",
|
||||
"chrono": "cpp",
|
||||
"codecvt": "cpp",
|
||||
"complex": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"deque": "cpp",
|
||||
"list": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"vector": "cpp",
|
||||
"exception": "cpp",
|
||||
"fstream": "cpp",
|
||||
"functional": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iomanip": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"memory": "cpp",
|
||||
"new": "cpp",
|
||||
"numeric": "cpp",
|
||||
"optional": "cpp",
|
||||
"ostream": "cpp",
|
||||
"ratio": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"string_view": "cpp",
|
||||
"system_error": "cpp",
|
||||
"thread": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"tuple": "cpp",
|
||||
"typeindex": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"utility": "cpp",
|
||||
"variant": "cpp",
|
||||
"algorithm": "cpp"
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
#include "database.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
|
||||
Database::Database(const std::string& dbname) : db_(nullptr)
|
||||
{
|
||||
|
@ -24,14 +24,16 @@ void Database::exec(const std::string& sql)
|
|||
|
||||
void Database::init()
|
||||
{
|
||||
std::string sqlCreateSellers{"CREATE TABLE IF NOT EXISTS sellers ("
|
||||
"id TEXT PRIMARY KEY NOT NULL, "
|
||||
"seller_no INTEGER, "
|
||||
"first_name TEXT, "
|
||||
"last_name TEXT, "
|
||||
"offered_articles INTEGER, "
|
||||
"UNIQUE (seller_no)"
|
||||
");"};
|
||||
std::string sqlCreateSellers{
|
||||
"CREATE TABLE IF NOT EXISTS sellers ("
|
||||
"id TEXT PRIMARY KEY NOT NULL, "
|
||||
"seller_no INTEGER, "
|
||||
"first_name TEXT, "
|
||||
"last_name TEXT, "
|
||||
"offered_articles INTEGER, "
|
||||
"UNIQUE (seller_no)"
|
||||
");"
|
||||
};
|
||||
|
||||
std::string sqlCreateArticles{
|
||||
"CREATE TABLE IF NOT EXISTS articles ("
|
||||
|
@ -44,7 +46,10 @@ void Database::init()
|
|||
"UNIQUE (source_no, article_no), "
|
||||
"FOREIGN KEY (seller_id) REFERENCES sellers(id) ON DELETE CASCADE, "
|
||||
"CHECK (article_no BETWEEN 0 AND 99999)"
|
||||
");"};
|
||||
");"
|
||||
};
|
||||
|
||||
std::cout << sqlCreateArticles << "\n";
|
||||
|
||||
beginTransaction();
|
||||
exec(sqlCreateSellers);
|
||||
|
|
|
@ -2,8 +2,8 @@ find_package(Boost COMPONENTS unit_test_framework REQUIRED)
|
|||
|
||||
add_executable(test_seller test_seller.cpp)
|
||||
target_link_libraries(test_seller core Boost::unit_test_framework)
|
||||
add_test(NAME Seller COMMAND ${CMAKE_BINARY_DIR}/bin/test_seller)
|
||||
add_test(Seller ${CMAKE_BINARY_DIR}/bin/test_seller)
|
||||
|
||||
add_executable(test_database test_database.cpp)
|
||||
target_link_libraries(test_database core Boost::unit_test_framework stdc++fs)
|
||||
add_test(NAME Database COMMAND ${CMAKE_BINARY_DIR}/bin/test_database)
|
||||
add_test(Database ${CMAKE_BINARY_DIR}/bin/test_database)
|
||||
|
|
|
@ -6,20 +6,11 @@
|
|||
|
||||
#include <boost/test/included/unit_test.hpp>
|
||||
|
||||
BOOST_AUTO_TEST_CASE(create_database)
|
||||
{
|
||||
std::filesystem::path testPath = std::filesystem::temp_directory_path() / "kima2test.db";
|
||||
if (std::filesystem::exists(testPath)) {
|
||||
std::filesystem::remove(testPath);
|
||||
}
|
||||
//using namespace boost::unit_test;
|
||||
|
||||
std::string filename = testPath.generic_string();
|
||||
|
||||
Database db(filename);
|
||||
BOOST_AUTO_TEST_CASE( create_database ) {
|
||||
std::filesystem::path testPath = std::filesystem::temp_directory_path() / "test.db";
|
||||
Database db(testPath.c_str());
|
||||
db.init();
|
||||
|
||||
BOOST_TEST(std::filesystem::exists(testPath) == true);
|
||||
if (std::filesystem::exists(testPath)) {
|
||||
std::filesystem::remove(testPath);
|
||||
}
|
||||
std::filesystem::remove(testPath);
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include <boost/test/included/unit_test.hpp>
|
||||
|
||||
//using namespace boost::unit_test;
|
||||
using namespace boost::unit_test;
|
||||
|
||||
BOOST_AUTO_TEST_CASE( create_uuid_nil ) {
|
||||
Seller seller{};
|
||||
|
|
Loading…
Reference in a new issue